Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

generic manager tests

  • Loading branch information...
commit 360d09408095ce1217b69be24e4031528b545d6e 1 parent 92a78a7
@evildmp authored
View
6 arkestra_utilities/managers.py
@@ -10,6 +10,12 @@ class ArkestraGenericModelManager(models.Manager):
def get_by_natural_key(self, slug):
return self.get(slug=slug)
+ 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(
Please sign in to comment.
Something went wrong with that request. Please try again.