Commits

Harro van der Klauw committed 6bd03cf

Added basic publication tests

Comments (0)

Files changed (1)

cmsplugin_news/tests.py

 Tests for the cmsplugin_news app
 """
 
+import datetime
+
 from django.test import TestCase
 
+from cmsplugin_news.models import News
+from cmsplugin_news.navigation import get_nodes
+
 class NewsTest(TestCase):
     def setUp(self):
-        pass  
+        self.today = datetime.datetime.today()
+        self.yesterday = self.today - datetime.timedelta(days=1)
+        self.tomorrow = self.today + datetime.timedelta(days=1)
         
     def tearDown(self):
         pass
+
         
     def test_unpublished(self):
         """
             Test if unpublished items are hidden by default
         """
-        pass
+        unpublished = News.objects.create(
+            title='Unpublished News',
+            slug='unpublished-news',
+            is_published=False,
+            pub_date=self.yesterday,
+        )
+        self.assertEquals(News.published.count(), 0)
+        unpublished.is_published = True
+        unpublished.save()
+        self.assertEquals(News.published.count(), 1)
+        unpublished.is_published = False
+        unpublished.save()
+        self.assertEquals(News.published.count(), 0)
+        
+        unpublished.delete()
         
     def test_future_published(self):
         """
             Tests that items with a future published date are hidden
         """
-        pass
+        future_published = News.objects.create(
+            title='Future published News',
+            slug='future-published-news',
+            is_published=True,
+            pub_date=self.tomorrow,
+        )
+        self.assertEquals(News.published.count(), 0)
+        future_published.pub_date = self.yesterday
+        future_published.save()
+        self.assertEquals(News.published.count(), 1)
+        future_published.pub_date = self.tomorrow
+        future_published.save()
+        self.assertEquals(News.published.count(), 0)
         
     def test_navigation(self):
         """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.