Debian Codegraph @

tests/custom_methods/tests.py

raw
1 from datetime import date
2
3 from django.test import TestCase
4
5 from .models import Article
6
7
8 class MethodsTests(TestCase):
9 def test_custom_methods(self):
10 a = Article.objects.create(
11 headline="Parrot programs in Python", pub_date=date(2005, 7, 27)
12 )
13 b = Article.objects.create(
14 headline="Beatles reunite", pub_date=date(2005, 7, 27)
15 )
16
17 self.assertFalse(a.was_published_today())
18 self.assertQuerySetEqual(
19 a.articles_from_same_day_1(),
20 [
21 "Beatles reunite",
22 ],
23 lambda a: a.headline,
24 )
25 self.assertQuerySetEqual(
26 a.articles_from_same_day_2(),
27 [
28 "Beatles reunite",
29 ],
30 lambda a: a.headline,
31 )
32
33 self.assertQuerySetEqual(
34 b.articles_from_same_day_1(),
35 [
36 "Parrot programs in Python",
37 ],
38 lambda a: a.headline,
39 )
40 self.assertQuerySetEqual(
41 b.articles_from_same_day_2(),
42 [
43 "Parrot programs in Python",
44 ],
45 lambda a: a.headline,
46 )