summaryrefslogtreecommitdiff
path: root/tests/modeltests
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-06-16 00:34:17 +0000
committerJustin Bronn <jbronn@gmail.com>2008-06-16 00:34:17 +0000
commit842dae0ed59cc7566cf35090093222ea3a61ec79 (patch)
tree9602bc18a8d3a7da81b2009ba8e7d51276bd1841 /tests/modeltests
parent4ec80c4333b618fc1ef2a02c7b8ca8719792f25f (diff)
gis: Merged revisions 7574-7583,7585-7586,7590-7602,7614-7615,7619-7625,7629,7632-7636 via svnmerge from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7642 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests')
-rw-r--r--tests/modeltests/basic/models.py5
-rw-r--r--tests/modeltests/many_to_many/models.py8
-rw-r--r--tests/modeltests/many_to_one/models.py6
-rw-r--r--tests/modeltests/model_inheritance/models.py5
-rw-r--r--tests/modeltests/one_to_one/models.py5
-rw-r--r--tests/modeltests/or_lookups/models.py5
-rw-r--r--tests/modeltests/test_client/fixtures/testdata.json18
-rw-r--r--tests/modeltests/update/models.py7
8 files changed, 51 insertions, 8 deletions
diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py
index d7c27cb15b..c3ad38d661 100644
--- a/tests/modeltests/basic/models.py
+++ b/tests/modeltests/basic/models.py
@@ -401,8 +401,9 @@ True
# The 'select' argument to extra() supports names with dashes in them, as long
# as you use values().
->>> Article.objects.filter(pub_date__year=2008).extra(select={'dashed-value': '1'}).values('headline', 'dashed-value')
-[{'headline': u'Article 11', 'dashed-value': 1}, {'headline': u'Article 12', 'dashed-value': 1}]
+>>> dicts = Article.objects.filter(pub_date__year=2008).extra(select={'dashed-value': '1'}).values('headline', 'dashed-value')
+>>> [sorted(d.items()) for d in dicts]
+[[('dashed-value', 1), ('headline', u'Article 11')], [('dashed-value', 1), ('headline', u'Article 12')]]
# If you use 'select' with extra() and names containing dashes on a query
# that's *not* a values() query, those extra 'select' values will silently be
diff --git a/tests/modeltests/many_to_many/models.py b/tests/modeltests/many_to_many/models.py
index e09fd825f8..c2ab2897b6 100644
--- a/tests/modeltests/many_to_many/models.py
+++ b/tests/modeltests/many_to_many/models.py
@@ -39,6 +39,14 @@ __test__ = {'API_TESTS':"""
# Create an Article.
>>> a1 = Article(id=None, headline='Django lets you build Web apps easily')
+
+# You can't associate it with a Publication until it's been saved.
+>>> a1.publications.add(p1)
+Traceback (most recent call last):
+...
+ValueError: 'Article' instance needs to have a primary key value before a many-to-many relationship can be used.
+
+# Save it!
>>> a1.save()
# Associate the Article with a Publication.
diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py
index 53ad4466bb..dfb17b8344 100644
--- a/tests/modeltests/many_to_one/models.py
+++ b/tests/modeltests/many_to_one/models.py
@@ -175,6 +175,12 @@ False
>>> Article.objects.filter(reporter__in=[r,r2]).distinct()
[<Article: John's second story>, <Article: Paul's story>, <Article: This is a test>]
+# You can also use a queryset instead of a literal list of instances.
+# The queryset must be reduced to a list of values using values(),
+# then converted into a query
+>>> Article.objects.filter(reporter__in=Reporter.objects.filter(first_name='John').values('pk').query).distinct()
+[<Article: John's second story>, <Article: This is a test>]
+
# You need two underscores between "reporter" and "id" -- not one.
>>> Article.objects.filter(reporter_id__exact=1)
Traceback (most recent call last):
diff --git a/tests/modeltests/model_inheritance/models.py b/tests/modeltests/model_inheritance/models.py
index b1a751f5e8..7c737b6bd1 100644
--- a/tests/modeltests/model_inheritance/models.py
+++ b/tests/modeltests/model_inheritance/models.py
@@ -147,8 +147,13 @@ Test constructor for Restaurant.
>>> c.save()
>>> ir = ItalianRestaurant(name='Ristorante Miron', address='1234 W. Ash', serves_hot_dogs=False, serves_pizza=False, serves_gnocchi=True, rating=4, chef=c)
>>> ir.save()
+>>> ItalianRestaurant.objects.filter(address='1234 W. Ash')
+[<ItalianRestaurant: Ristorante Miron the italian restaurant>]
+
>>> ir.address = '1234 W. Elm'
>>> ir.save()
+>>> ItalianRestaurant.objects.filter(address='1234 W. Elm')
+[<ItalianRestaurant: Ristorante Miron the italian restaurant>]
# Make sure Restaurant and ItalianRestaurant have the right fields in the right
# order.
diff --git a/tests/modeltests/one_to_one/models.py b/tests/modeltests/one_to_one/models.py
index 800ccddac2..6fa4dd8c18 100644
--- a/tests/modeltests/one_to_one/models.py
+++ b/tests/modeltests/one_to_one/models.py
@@ -80,11 +80,8 @@ DoesNotExist: Restaurant matching query does not exist.
>>> r.place
<Place: Ace Hardware the place>
-# Set the place back again, using assignment in the reverse direction. Need to
-# reload restaurant object first, because the reverse set can't update the
-# existing restaurant instance
+# Set the place back again, using assignment in the reverse direction.
>>> p1.restaurant = r
->>> r.save()
>>> p1.restaurant
<Restaurant: Demon Dogs the restaurant>
diff --git a/tests/modeltests/or_lookups/models.py b/tests/modeltests/or_lookups/models.py
index c779e19e37..22bada07b1 100644
--- a/tests/modeltests/or_lookups/models.py
+++ b/tests/modeltests/or_lookups/models.py
@@ -110,8 +110,9 @@ __test__ = {'API_TESTS':"""
>>> Article.objects.filter(Q(headline__startswith='Hello') | Q(headline__contains='bye')).count()
3
->>> list(Article.objects.filter(Q(headline__startswith='Hello'), Q(headline__contains='bye')).values())
-[{'headline': u'Hello and goodbye', 'pub_date': datetime.datetime(2005, 11, 29, 0, 0), 'id': 3}]
+>>> dicts = list(Article.objects.filter(Q(headline__startswith='Hello'), Q(headline__contains='bye')).values())
+>>> [sorted(d.items()) for d in dicts]
+[[('headline', u'Hello and goodbye'), ('id', 3), ('pub_date', datetime.datetime(2005, 11, 29, 0, 0))]]
>>> Article.objects.filter(Q(headline__startswith='Hello')).in_bulk([1,2])
{1: <Article: Hello>}
diff --git a/tests/modeltests/test_client/fixtures/testdata.json b/tests/modeltests/test_client/fixtures/testdata.json
index e9d3ebe9a8..0dcf625939 100644
--- a/tests/modeltests/test_client/fixtures/testdata.json
+++ b/tests/modeltests/test_client/fixtures/testdata.json
@@ -34,5 +34,23 @@
"email": "testclient@example.com",
"date_joined": "2006-12-17 07:03:31"
}
+ },
+ {
+ "pk": "3",
+ "model": "auth.user",
+ "fields": {
+ "username": "staff",
+ "first_name": "Staff",
+ "last_name": "Member",
+ "is_active": true,
+ "is_superuser": false,
+ "is_staff": true,
+ "last_login": "2006-12-17 07:03:31",
+ "groups": [],
+ "user_permissions": [],
+ "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161",
+ "email": "testclient@example.com",
+ "date_joined": "2006-12-17 07:03:31"
+ }
}
] \ No newline at end of file
diff --git a/tests/modeltests/update/models.py b/tests/modeltests/update/models.py
index 3b0f83389f..8a35b61a7c 100644
--- a/tests/modeltests/update/models.py
+++ b/tests/modeltests/update/models.py
@@ -63,5 +63,12 @@ a manager method.
>>> DataPoint.objects.values('value').distinct()
[{'value': u'thing'}]
+We do not support update on already sliced query sets.
+
+>>> DataPoint.objects.all()[:2].update(another_value='another thing')
+Traceback (most recent call last):
+ ...
+AssertionError: Cannot update a query once a slice has been taken.
+
"""
}