-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into partial-indexes
- Loading branch information
Showing
7 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.test import SimpleTestCase | ||
|
||
from django_mongodb.fields import ObjectIdAutoField | ||
|
||
|
||
class MethodTests(SimpleTestCase): | ||
def test_deconstruct(self): | ||
field = ObjectIdAutoField() | ||
name, path, args, kwargs = field.deconstruct() | ||
self.assertEqual(path, "django_mongodb.fields.ObjectIdAutoField") | ||
self.assertEqual(args, []) | ||
self.assertEqual(kwargs, {"primary_key": True}) | ||
|
||
def test_to_python(self): | ||
f = ObjectIdAutoField() | ||
self.assertEqual(f.to_python("1"), 1) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.db import models | ||
|
||
|
||
class Author(models.Model): | ||
name = models.CharField(max_length=10) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class Book(models.Model): | ||
title = models.CharField(max_length=10) | ||
author = models.ForeignKey(Author, models.CASCADE) | ||
|
||
def __str__(self): | ||
return self.title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.test import TestCase | ||
|
||
from .models import Author, Book | ||
|
||
|
||
class MQLTests(TestCase): | ||
def test_all(self): | ||
with self.assertNumQueries(1) as ctx: | ||
list(Author.objects.all()) | ||
query = ctx.captured_queries[0]["sql"] | ||
self.assertEqual(query, "db.queries__author.aggregate([{'$match': {'$expr': {}}}])") | ||
|
||
def test_join(self): | ||
with self.assertNumQueries(1) as ctx: | ||
list(Book.objects.filter(author__name="Bob")) | ||
query = ctx.captured_queries[0]["sql"] | ||
self.assertEqual( | ||
query, | ||
"db.queries__book.aggregate([" | ||
"{'$lookup': {'from': 'queries__author', " | ||
"'let': {'parent__field__0': '$author_id'}, " | ||
"'pipeline': [{'$match': {'$expr': " | ||
"{'$and': [{'$eq': ['$$parent__field__0', '$_id']}]}}}], 'as': 'queries__author'}}, " | ||
"{'$unwind': '$queries__author'}, " | ||
"{'$match': {'$expr': {'$eq': ['$queries__author.name', 'Bob']}}}])", | ||
) |