Skip to content

Commit 2491a02

Browse files
committed
Add more unit test.
1 parent c2a8578 commit 2491a02

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

django_mongodb_backend/features.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
8686
# Value.as_mql() doesn't call output_field.get_db_prep_save():
8787
# https://github.com/mongodb/django-mongodb-backend/issues/282
8888
"model_fields.test_jsonfield.TestSaveLoad.test_bulk_update_custom_get_prep_value",
89+
"model_fields_.test_embedded_model_array.QueryingTests.test_array_annotation_index",
8990
}
9091
# $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3.
9192
_django_test_expected_failures_bitwise = {

tests/model_fields_/test_embedded_model_array.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,29 @@ def test_array_as_rhs(self):
310310
)
311311
self.assertCountEqual(result, [self.new_descoveries])
312312

313+
def test_array_annotation_as_rhs(self):
314+
result = Exhibit.objects.annotate(
315+
section_numbers=models.F("main_section__section_number")
316+
).filter(section_numbers__in=models.F("sections__section_number"))
317+
self.assertCountEqual(result, [self.new_descoveries])
318+
319+
def test_array_annotation_index(self):
320+
# This test would be useful to have, but it cannot be implemented
321+
# due to the current annotation handling.
322+
# Supporting slicing or indexing over an annotated
323+
# Embedded Array Field would require a refactor.
324+
result = Exhibit.objects.annotate(
325+
section_numbers=models.F("sections__section_number")
326+
).filter(section_numbers__0=1)
327+
self.assertCountEqual(result, [self.new_descoveries, self.egypt])
328+
329+
def test_array_annotation(self):
330+
results = Exhibit.objects.annotate(
331+
section_numbers=models.F("sections__section_number")
332+
).all()
333+
sections_numbers = [e.section_numbers for e in results]
334+
self.assertCountEqual(sections_numbers, [[1], [1, 2], [2], []])
335+
313336

314337
@isolate_apps("model_fields_")
315338
class CheckTests(SimpleTestCase):

0 commit comments

Comments
 (0)