summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-11-10 05:36:41 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-11-10 05:36:41 +0000
commite3e37ed1202f58e4d5e172ecd15af5ab8eda3492 (patch)
tree9c57b12cb260c903f7d2142be06e20a9950b82dc /tests
parent28bce49e59a4dac2ef0fdb14af4ff5b09c5efc95 (diff)
Fixed #724 -- Ensured get_next_by_FOO() and get_previous_by_FOO() methods don't skip or duplicate any records in the case of duplicate values. Thanks for reporting the bug, mattycakes@gmail.com
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1155 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/testapp/models/lookup.py39
1 files changed, 29 insertions, 10 deletions
diff --git a/tests/testapp/models/lookup.py b/tests/testapp/models/lookup.py
index deb5d807ef..6d8ede1905 100644
--- a/tests/testapp/models/lookup.py
+++ b/tests/testapp/models/lookup.py
@@ -30,6 +30,8 @@ API_TESTS = """
>>> a5.save()
>>> a6 = articles.Article(headline='Article 6', pub_date=datetime(2005, 8, 1, 8, 0))
>>> a6.save()
+>>> a7 = articles.Article(headline='Article 7', pub_date=datetime(2005, 7, 27))
+>>> a7.save()
# get_iterator() is just like get_list(), but it's a generator.
>>> for a in articles.get_iterator():
@@ -39,6 +41,7 @@ Article 6
Article 4
Article 2
Article 3
+Article 7
Article 1
# get_iterator() takes the same lookup arguments as get_list().
@@ -48,9 +51,9 @@ Article 4
# get_count() returns the number of objects matching search criteria.
>>> articles.get_count()
-6L
+7L
>>> articles.get_count(pub_date__exact=datetime(2005, 7, 27))
-2L
+3L
>>> articles.get_count(headline__startswith='Blah blah')
0L
@@ -67,10 +70,10 @@ Article 4
# dictionaries instead of object instances -- and you can specify which fields
# you want to retrieve.
>>> articles.get_values(fields=['headline'])
-[{'headline': 'Article 5'}, {'headline': 'Article 6'}, {'headline': 'Article 4'}, {'headline': 'Article 2'}, {'headline': 'Article 3'}, {'headline': 'Article 1'}]
+[{'headline': 'Article 5'}, {'headline': 'Article 6'}, {'headline': 'Article 4'}, {'headline': 'Article 2'}, {'headline': 'Article 3'}, {'headline': 'Article 7'}, {'headline': 'Article 1'}]
>>> articles.get_values(pub_date__exact=datetime(2005, 7, 27), fields=['id'])
-[{'id': 2}, {'id': 3}]
->>> articles.get_values(fields=['id', 'headline']) == [{'id': 5, 'headline': 'Article 5'}, {'id': 6, 'headline': 'Article 6'}, {'id': 4, 'headline': 'Article 4'}, {'id': 2, 'headline': 'Article 2'}, {'id': 3, 'headline': 'Article 3'}, {'id': 1, 'headline': 'Article 1'}]
+[{'id': 2}, {'id': 3}, {'id': 7}]
+>>> articles.get_values(fields=['id', 'headline']) == [{'id': 5, 'headline': 'Article 5'}, {'id': 6, 'headline': 'Article 6'}, {'id': 4, 'headline': 'Article 4'}, {'id': 2, 'headline': 'Article 2'}, {'id': 3, 'headline': 'Article 3'}, {'id': 7, 'headline': 'Article 7'}, {'id': 1, 'headline': 'Article 1'}]
True
# get_values_iterator() is just like get_values(), but it's a generator.
@@ -83,24 +86,40 @@ True
[('headline', 'Article 4'), ('id', 4)]
[('headline', 'Article 2'), ('id', 2)]
[('headline', 'Article 3'), ('id', 3)]
+[('headline', 'Article 7'), ('id', 7)]
[('headline', 'Article 1'), ('id', 1)]
# Every DateField and DateTimeField creates get_next_by_FOO() and
# get_previous_by_FOO() methods.
+# In the case of identical date values, these methods will use the ID as a
+# fallback check. This guarantees that no records are skipped or duplicated.
+>>> a1.get_next_by_pub_date()
+Article 2
+>>> a2.get_next_by_pub_date()
+Article 3
>>> a3.get_next_by_pub_date()
-Article 4
->>> a2.get_previous_by_pub_date()
-Article 1
-
-# get_next_by_FOO() and get_previous_by_FOO() take the time into account.
+Article 7
>>> a4.get_next_by_pub_date()
Article 6
>>> a5.get_next_by_pub_date()
Traceback (most recent call last):
...
ArticleDoesNotExist: Article does not exist for ...
+>>> a6.get_next_by_pub_date()
+Article 5
+>>> a7.get_next_by_pub_date()
+Article 4
+
+>>> a7.get_previous_by_pub_date()
+Article 3
>>> a6.get_previous_by_pub_date()
Article 4
>>> a5.get_previous_by_pub_date()
Article 6
+>>> a4.get_previous_by_pub_date()
+Article 7
+>>> a3.get_previous_by_pub_date()
+Article 2
+>>> a2.get_previous_by_pub_date()
+Article 1
"""