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())
|
2022-09-24 10:29:58 +00:00
|
|
|
self.assertQuerySetEqual(
|
2022-02-03 19:24:19 +00:00
|
|
|
a.articles_from_same_day_1(),
|
|
|
|
[
|
2010-09-12 20:03:03 +00:00
|
|
|
"Beatles reunite",
|
|
|
|
],
|
|
|
|
lambda a: a.headline,
|
|
|
|
)
|
2022-09-24 10:29:58 +00:00
|
|
|
self.assertQuerySetEqual(
|
2022-02-03 19:24:19 +00:00
|
|
|
a.articles_from_same_day_2(),
|
|
|
|
[
|
2010-09-12 20:03:03 +00:00
|
|
|
"Beatles reunite",
|
|
|
|
],
|
2022-02-03 19:24:19 +00:00
|
|
|
lambda a: a.headline,
|
2010-09-12 20:03:03 +00:00
|
|
|
)
|
|
|
|
|
2022-09-24 10:29:58 +00:00
|
|
|
self.assertQuerySetEqual(
|
2022-02-03 19:24:19 +00:00
|
|
|
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,
|
|
|
|
)
|
2022-09-24 10:29:58 +00:00
|
|
|
self.assertQuerySetEqual(
|
2022-02-03 19:24:19 +00:00
|
|
|
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
|
|
|
],
|
2022-02-03 19:24:19 +00:00
|
|
|
lambda a: a.headline,
|
2010-09-12 20:03:03 +00:00
|
|
|
)
|