Skip to content
Browse files

Merge pull request #99 from evildmp/genericmanagertests

Genericmanagertests
  • Loading branch information...
2 parents 145d839 + 911b28b commit ebf4c971e55db2b312822316a1ec560018dd9018 @evildmp committed
Showing with 65 additions and 4 deletions.
  1. +7 −0 arkestra_utilities/managers.py
  2. +49 −0 arkestra_utilities/tests.py
  3. +9 −4 news_and_events/tests.py
View
7 arkestra_utilities/managers.py
@@ -10,6 +10,13 @@ class ArkestraGenericModelManager(models.Manager):
def get_by_natural_key(self, slug):
return self.get(slug=slug)
+ # this method is not yet used, but will be used as part of the wholesale rewriting of this code
+ def published_items(self, entity=None):
+ return self.model.objects.filter(
+ published=True,
+ date__lte = datetime.now()
+ )
+
def get_items(self, instance):
publishable_items = self.get_publishable_items(instance)
if instance.order_by == "importance/date":
View
49 arkestra_utilities/tests.py
@@ -0,0 +1,49 @@
+from datetime import datetime, timedelta
+
+from django.test import TestCase
+from django.test.client import Client
+
+from news_and_events.models import NewsArticle
+
+class NewsManagerTests(TestCase):
+ def setUp(self):
+ # Every test needs a client.
+ self.client = Client()
+
+ # create a news item
+ self.tootharticle = NewsArticle(
+ title = "All about teeth",
+ slug = "all-about-teeth",
+ )
+
+ def test_published_items_no_saved_items(self):
+ self.assertEqual(
+ list(NewsArticle.objects.published_items()),
+ []
+ )
+
+ def test_published_items_one_saved_item_unpublished(self):
+ self.tootharticle.date = datetime.now() - timedelta(minutes=30)
+ self.tootharticle.save()
+ self.assertEqual(
+ list(NewsArticle.objects.published_items()),
+ []
+ )
+
+ def test_published_items_one_saved_published_but_future_item(self):
+ self.tootharticle.published = True
+ self.tootharticle.date = datetime.now() + timedelta(minutes=30)
+ self.tootharticle.save()
+ self.assertEqual(
+ list(NewsArticle.objects.published_items()),
+ []
+ )
+
+ def test_published_items_one_saved_published_item(self):
+ self.tootharticle.published = True
+ self.tootharticle.date = datetime.now() - timedelta(minutes=30)
+ self.tootharticle.save()
+ self.assertEqual(
+ list(NewsArticle.objects.published_items()),
+ [self.tootharticle]
+ )
View
13 news_and_events/tests.py
@@ -6,13 +6,18 @@
from django.contrib.auth.models import User
# we're testing the behaviour of a method that uses date-related functions
-import datetime
+from datetime import datetime, timedelta
from cms.api import create_page
-from models import NewsArticle
+from news_and_events.models import NewsArticle
from contacts_and_people.models import Entity
+@override_settings(
+ USE_TZ = False
+)
+
+
class NewsTests(TestCase):
def setUp(self):
# Every test needs a client.
@@ -28,7 +33,7 @@ def setUp(self):
self.tootharticle = NewsArticle(
title = "All about teeth",
slug = "all-about-teeth",
- date = datetime.datetime.now() + datetime.timedelta(days=30),
+ date = datetime.now(),
)
def test_generic_attributes(self):
@@ -43,7 +48,7 @@ def test_generic_attributes(self):
self.assertEqual(self.tootharticle.get_template, settings.CMS_TEMPLATES[0][0])
def test_date_related_attributes(self):
- self.tootharticle.date = datetime.datetime(year=2012, month=12, day=12)
+ self.tootharticle.date = datetime(year=2012, month=12, day=12)
self.assertEqual(self.tootharticle.get_when, "December 2012")
@override_settings(

0 comments on commit ebf4c97

Please sign in to comment.
Something went wrong with that request. Please try again.