Skip to content

Commit 598d002

Browse files
committed
fix join tests following foreignField/localField refactor
1 parent ed476a7 commit 598d002

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

tests/encryption_/test_fields.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from bson import ObjectId
77
from django.db import DatabaseError
8-
from django.db.models import Avg
8+
from django.db.models import Avg, F
99

1010
from django_mongodb_backend.fields import (
1111
EncryptedArrayField,
@@ -18,6 +18,7 @@
1818
from .models import (
1919
Actor,
2020
ArrayModel,
21+
Author,
2122
BigIntegerModel,
2223
Billing,
2324
BinaryModel,
@@ -313,25 +314,27 @@ def test_get_or_create(self):
313314
self.assertEqual(obj1, obj2)
314315

315316
def test_join(self):
317+
book = Book.objects.create(title="Book", author=Author.objects.create(name="Bob"))
318+
self.assertSequenceEqual(Book.objects.filter(author__name="Bob"), [book])
319+
320+
def test_join_with_let(self):
316321
msg = (
317322
"Non-empty 'let' field is not allowed in the $lookup aggregation "
318323
"stage over an encrypted collection."
319324
)
320325
with self.assertRaisesMessage(DatabaseError, msg):
321-
list(Book.objects.filter(author__name="xxx"))
326+
list(Book.objects.filter(author__name=F("title")))
322327

323328
def test_order_by(self):
324329
msg = "Cannot add an encrypted field as a prefix of another encrypted field"
325330
with self.assertRaisesMessage(DatabaseError, msg):
326331
list(CharModel.objects.order_by("value"))
327332

328333
def test_select_related(self):
329-
msg = (
330-
"Non-empty 'let' field is not allowed in the $lookup aggregation "
331-
"stage over an encrypted collection."
332-
)
333-
with self.assertRaisesMessage(DatabaseError, msg):
334-
list(Book.objects.select_related("author"))
334+
Book.objects.create(title="Book", author=Author.objects.create(name="Bob"))
335+
with self.assertNumQueries(1, using="encrypted"):
336+
books = Book.objects.select_related("author")
337+
self.assertEqual(books[0].author.name, "Bob")
335338

336339
def test_update(self):
337340
msg = "Multi-document updates are not allowed with Queryable Encryption"

0 commit comments

Comments
 (0)