Commits

Harro van der Klauw  committed 6bd03cf

Added basic publication tests

  • Participants
  • Parent commits 633b0f3

Comments (0)

Files changed (1)

File 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):
         """