2013-07-29 17:19:04 +00:00
|
|
|
from __future__ import unicode_literals
|
2011-10-13 18:04:12 +00:00
|
|
|
|
2010-09-12 20:03:03 +00:00
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
|
2011-10-13 18:04:12 +00:00
|
|
|
from .models import Article
|
2010-09-12 20:03:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MethodsTests(TestCase):
|
|
|
|
def test_custom_methods(self):
|
|
|
|
a = Article.objects.create(
|
2015-08-22 18:05:54 +00:00
|
|
|
headline="Parrot programs in Python", pub_date=date(2005, 7, 27)
|
2010-09-12 20:03:03 +00:00
|
|
|
)
|
|
|
|
b = Article.objects.create(
|
|
|
|
headline="Beatles reunite", pub_date=date(2005, 7, 27)
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertFalse(a.was_published_today())
|
|
|
|
self.assertQuerysetEqual(
|
|
|
|
a.articles_from_same_day_1(), [
|
|
|
|
"Beatles reunite",
|
|
|
|
],
|
|
|
|
lambda a: a.headline,
|
|
|
|
)
|
|
|
|
self.assertQuerysetEqual(
|
|
|
|
a.articles_from_same_day_2(), [
|
|
|
|
"Beatles reunite",
|
|
|
|
],
|
|
|
|
lambda a: a.headline
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertQuerysetEqual(
|
|
|
|
b.articles_from_same_day_1(), [
|
2015-08-22 18:05:54 +00:00
|
|
|
"Parrot programs in Python",
|
2010-09-12 20:03:03 +00:00
|
|
|
],
|
|
|
|
lambda a: a.headline,
|
|
|
|
)
|
|
|
|
self.assertQuerysetEqual(
|
|
|
|
b.articles_from_same_day_2(), [
|
2015-08-22 18:05:54 +00:00
|
|
|
"Parrot programs in Python",
|
2010-09-12 20:03:03 +00:00
|
|
|
],
|
|
|
|
lambda a: a.headline
|
|
|
|
)
|