summaryrefslogtreecommitdiff
path: root/tests/regressiontests/mongodb
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2010-06-19 01:26:36 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2010-06-19 01:26:36 +0000
commitd19cba9b8cc03abe7c0007b74f79adb25754a756 (patch)
tree9667728a3b729d035f38b3f6963e54cfc77c523e /tests/regressiontests/mongodb
parent2804e22bfec198fbef24c9ba3fc6bde2d9ec04f0 (diff)
[soc2010/query-refactor] Implemented not equal (exclude(foo=bar)) in the ORM for MongoDB, note that this doesn't actually work at the moment due to a bug in MongoDB.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13358 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/mongodb')
-rw-r--r--tests/regressiontests/mongodb/models.py2
-rw-r--r--tests/regressiontests/mongodb/tests.py23
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/regressiontests/mongodb/models.py b/tests/regressiontests/mongodb/models.py
index b942d12e59..183663aaf5 100644
--- a/tests/regressiontests/mongodb/models.py
+++ b/tests/regressiontests/mongodb/models.py
@@ -15,3 +15,5 @@ class Artist(models.Model):
class Group(models.Model):
id = models.NativeAutoField(primary_key=True)
name = models.CharField(max_length=255)
+ year_formed = models.IntegerField(null=True)
+
diff --git a/tests/regressiontests/mongodb/tests.py b/tests/regressiontests/mongodb/tests.py
index bd9cd5981f..93adcecd58 100644
--- a/tests/regressiontests/mongodb/tests.py
+++ b/tests/regressiontests/mongodb/tests.py
@@ -57,3 +57,26 @@ class MongoTestCase(TestCase):
self.assertEqual(b.current_group_id, e.pk)
self.assertFalse(hasattr(b, "_current_group_cache"))
self.assertEqual(b.current_group, e)
+
+ def test_lookup(self):
+ q = Group.objects.create(name="Queen", year_formed=1971)
+ e = Group.objects.create(name="The E Street Band", year_formed=1972)
+
+ qs = Group.objects.exclude(year_formed=1972)
+ v = qs.query.get_compiler(qs.db).get_filters(qs.query.where, correct=True)
+ self.assertEqual(v, {
+ "$or": [
+ {"year_formed": {"$ne": 1972}},
+ {"year_formed": None},
+ ]
+ })
+ # A bug in MongoDB prevents this query from actually working, but test
+ # that we're at least generating the right query.
+ return
+
+ self.assertQuerysetEqual(
+ qs, [
+ "Queen",
+ ],
+ lambda g: g.name,
+ )