diff options
Diffstat (limited to 'tests/custom_methods')
| -rw-r--r-- | tests/custom_methods/models.py | 9 | ||||
| -rw-r--r-- | tests/custom_methods/tests.py | 16 |
2 files changed, 16 insertions, 9 deletions
diff --git a/tests/custom_methods/models.py b/tests/custom_methods/models.py index f44d1b8265..1ff823297d 100644 --- a/tests/custom_methods/models.py +++ b/tests/custom_methods/models.py @@ -28,11 +28,14 @@ class Article(models.Model): database query for the sake of demonstration. """ from django.db import connection + with connection.cursor() as cursor: - cursor.execute(""" + cursor.execute( + """ SELECT id, headline, pub_date FROM custom_methods_article WHERE pub_date = %s - AND id != %s""", [connection.ops.adapt_datefield_value(self.pub_date), - self.id]) + AND id != %s""", + [connection.ops.adapt_datefield_value(self.pub_date), self.id], + ) return [self.__class__(*row) for row in cursor.fetchall()] diff --git a/tests/custom_methods/tests.py b/tests/custom_methods/tests.py index bbcec1f9f2..2bae2d2623 100644 --- a/tests/custom_methods/tests.py +++ b/tests/custom_methods/tests.py @@ -16,27 +16,31 @@ class MethodsTests(TestCase): self.assertFalse(a.was_published_today()) self.assertQuerysetEqual( - a.articles_from_same_day_1(), [ + a.articles_from_same_day_1(), + [ "Beatles reunite", ], lambda a: a.headline, ) self.assertQuerysetEqual( - a.articles_from_same_day_2(), [ + a.articles_from_same_day_2(), + [ "Beatles reunite", ], - lambda a: a.headline + lambda a: a.headline, ) self.assertQuerysetEqual( - b.articles_from_same_day_1(), [ + b.articles_from_same_day_1(), + [ "Parrot programs in Python", ], lambda a: a.headline, ) self.assertQuerysetEqual( - b.articles_from_same_day_2(), [ + b.articles_from_same_day_2(), + [ "Parrot programs in Python", ], - lambda a: a.headline + lambda a: a.headline, ) |
