diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2010-07-19 20:36:07 +0000 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2010-07-19 20:36:07 +0000 |
| commit | a35cbdbeafb478aeaa281c4d38821affbb47ff37 (patch) | |
| tree | 55e208a38dc9e18704696e4b05ca5a2c9d8c79f5 /tests/regressiontests/mongodb | |
| parent | 485bfe486148783870568ba7e47d41d8ab794069 (diff) | |
[soc2010/query-refactor] On unsupported operations raise a useful exception.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13437 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/mongodb')
| -rw-r--r-- | tests/regressiontests/mongodb/models.py | 3 | ||||
| -rw-r--r-- | tests/regressiontests/mongodb/tests.py | 37 |
2 files changed, 37 insertions, 3 deletions
diff --git a/tests/regressiontests/mongodb/models.py b/tests/regressiontests/mongodb/models.py index 039fce4930..274c1936a1 100644 --- a/tests/regressiontests/mongodb/models.py +++ b/tests/regressiontests/mongodb/models.py @@ -7,7 +7,8 @@ class Artist(models.Model): good = models.BooleanField() age = models.IntegerField(null=True) - current_group = models.ForeignKey("Group", null=True) + current_group = models.ForeignKey("Group", null=True, + related_name="current_artists") def __unicode__(self): return self.name diff --git a/tests/regressiontests/mongodb/tests.py b/tests/regressiontests/mongodb/tests.py index 54c36094cf..01bdd6c13a 100644 --- a/tests/regressiontests/mongodb/tests.py +++ b/tests/regressiontests/mongodb/tests.py @@ -1,5 +1,5 @@ -from django.db import connection -from django.db.models import Count, F +from django.db import connection, UnsupportedDatabaseOperation +from django.db.models import Count, Sum, F from django.test import TestCase from models import Artist, Group @@ -359,3 +359,36 @@ class MongoTestCase(TestCase): # Ensure that closing a connection that was never established doesn't # blow up. connection.close() + + def assert_unsupported(self, obj): + if callable(obj): + # Queryset wrapped in a function (for aggregates and such) + self.assertRaises(UnsupportedDatabaseOperation, obj) + else: + # Just a queryset that blows up on evaluation + self.assertRaises(UnsupportedDatabaseOperation, list, obj) + + def test_unsupported_ops(self): + self.assert_unsupported( + Artist.objects.filter(current_group__name="The Beatles") + ) + + self.assert_unsupported( + Artist.objects.extra(select={"a": "1.0"}) + ) + + self.assert_unsupported( + Group.objects.annotate(artists=Count("current_artists")) + ) + + self.assert_unsupported( + lambda: Artist.objects.aggregate(Sum("age")) + ) + + self.assert_unsupported( + lambda: Artist.objects.aggregate(Count("age")) + ) + + self.assert_unsupported( + lambda: Artist.objects.aggregate(Count("id"), Count("pk")) + ) |
