2010-09-13 04:03:03 +08:00
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
|
2011-10-14 02:04:12 +08:00
|
|
|
from .models import Article
|
2010-09-13 04:03:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
class MethodsTests(TestCase):
|
|
|
|
def test_custom_methods(self):
|
|
|
|
a = Article.objects.create(
|
2015-08-23 02:05:54 +08:00
|
|
|
headline="Parrot programs in Python", pub_date=date(2005, 7, 27)
|
2010-09-13 04:03:03 +08:00
|
|
|
)
|
|
|
|
b = Article.objects.create(
|
|
|
|
headline="Beatles reunite", pub_date=date(2005, 7, 27)
|
|
|
|
)
|
|
|
|
|
|
|
|
self.assertFalse(a.was_published_today())
|
2022-09-24 18:29:58 +08:00
|
|
|
self.assertQuerySetEqual(
|
2010-09-13 04:03:03 +08:00
|
|
|
a.articles_from_same_day_1(),
|
|
|
|
[
|
|
|
|
"Beatles reunite",
|
|
|
|
],
|
|
|
|
lambda a: a.headline,
|
|
|
|
)
|
2022-09-24 18:29:58 +08:00
|
|
|
self.assertQuerySetEqual(
|
2010-09-13 04:03:03 +08:00
|
|
|
a.articles_from_same_day_2(),
|
|
|
|
[
|
|
|
|
"Beatles reunite",
|
|
|
|
],
|
|
|
|
lambda a: a.headline,
|
|
|
|
)
|
|
|
|
|
2022-09-24 18:29:58 +08:00
|
|
|
self.assertQuerySetEqual(
|
2010-09-13 04:03:03 +08:00
|
|
|
b.articles_from_same_day_1(),
|
|
|
|
[
|
2015-08-23 02:05:54 +08:00
|
|
|
"Parrot programs in Python",
|
2010-09-13 04:03:03 +08:00
|
|
|
],
|
|
|
|
lambda a: a.headline,
|
|
|
|
)
|
2022-09-24 18:29:58 +08:00
|
|
|
self.assertQuerySetEqual(
|
2010-09-13 04:03:03 +08:00
|
|
|
b.articles_from_same_day_2(),
|
|
|
|
[
|
2015-08-23 02:05:54 +08:00
|
|
|
"Parrot programs in Python",
|
2010-09-13 04:03:03 +08:00
|
|
|
],
|
|
|
|
lambda a: a.headline,
|
|
|
|
)
|