1
1
from datetime import date
2
2
3
- from django .db import models
3
+ from django .db import connection , models
4
4
from django .test import SimpleTestCase , TestCase
5
- from django .test .utils import isolate_apps
5
+ from django .test .utils import CaptureQueriesContext , isolate_apps
6
6
7
7
from django_mongodb_backend .fields import EmbeddedModelArrayField
8
8
from django_mongodb_backend .models import EmbeddedModel
@@ -93,11 +93,8 @@ def setUpTestData(cls):
93
93
artifacts = [
94
94
ArtifactDetail (
95
95
name = "Ptolemaic Crown" ,
96
- description = "Royal headpiece worn by Ptolemy kings." ,
97
96
metadata = {
98
- "material" : "gold" ,
99
97
"origin" : "Egypt" ,
100
- "era" : "Ptolemaic Period" ,
101
98
},
102
99
)
103
100
],
@@ -112,57 +109,50 @@ def setUpTestData(cls):
112
109
artifacts = [
113
110
ArtifactDetail (
114
111
name = "Statue of Zeus" ,
115
- description = "One of the Seven Wonders, created by Phidias." ,
116
112
metadata = {"location" : "Olympia" , "height_m" : 12 },
117
113
),
118
114
ArtifactDetail (
119
115
name = "Hanging Gardens" ,
120
- description = "Legendary gardens of Babylon." ,
121
- metadata = {"debated_existence" : True },
122
116
),
123
117
],
124
118
),
119
+ ],
120
+ )
121
+ cls .new_descoveries = MuseumExhibit .objects .create (
122
+ exhibit_name = "New Discoveries" ,
123
+ sections = [
125
124
ExhibitSection (
126
- section_number = 2 ,
125
+ section_number = 1 ,
127
126
artifacts = [
128
127
ArtifactDetail (
129
128
name = "Lighthouse of Alexandria" ,
130
- description = "Guided sailors safely to port." ,
131
129
metadata = {"height_m" : 100 , "built" : "3rd century BC" },
132
130
)
133
131
],
134
- ),
132
+ )
135
133
],
136
134
)
137
- cls .new_descoveries = MuseumExhibit .objects .create (
138
- exhibit_name = "New Discoveries" ,
139
- sections = [ExhibitSection (section_number = 1 , artifacts = [])],
140
- )
141
135
cls .lost_empires = MuseumExhibit .objects .create (
142
136
exhibit_name = "Lost Empires" ,
143
137
main_section = ExhibitSection (
144
138
section_number = 3 ,
145
139
artifacts = [
146
140
ArtifactDetail (
147
141
name = "Bronze Statue" ,
148
- description = "Statue from the Hellenistic period." ,
149
- metadata = {"origin" : "Pergamon" , "material" : "bronze" },
142
+ metadata = {"origin" : "Pergamon" },
150
143
restorations = [
151
144
RestorationRecord (
152
145
date = date (1998 , 4 , 15 ),
153
- description = "Removed oxidized layer." ,
154
- restored_by = "Restoration Lab A" ,
146
+ restored_by = "Zacarias" ,
155
147
),
156
148
RestorationRecord (
157
149
date = date (2010 , 7 , 22 ),
158
- description = "Reinforced the base structure." ,
159
- restored_by = "Dr. Liu Cheng" ,
150
+ restored_by = "Vicente" ,
160
151
),
161
152
],
162
153
last_restoration = RestorationRecord (
163
154
date = date (2010 , 7 , 22 ),
164
- description = "Reinforced the base structure." ,
165
- restored_by = "Dr. Liu Cheng" ,
155
+ restored_by = "Monzon" ,
166
156
),
167
157
)
168
158
],
@@ -188,6 +178,15 @@ def test_filter_with_embeddedfield_array_path(self):
188
178
[self .lost_empires ],
189
179
)
190
180
181
+ def test_filter_unsupported_lookups (self ):
182
+ # handle the unsupported lookups as key in a keytransform
183
+
184
+ for lookup in ["contained_by" , "contains" , "contains" , "range" ]:
185
+ kwargs = {f"main_section__artifacts__metadata__origin__{ lookup } " : ["Pergamon" , "Egypt" ]}
186
+ with CaptureQueriesContext (connection ) as captured_queries :
187
+ self .assertCountEqual (MuseumExhibit .objects .filter (** kwargs ), [])
188
+ self .assertIn (f"'field': '{ lookup } '" , captured_queries [0 ]["sql" ])
189
+
191
190
def test_len (self ):
192
191
self .assertCountEqual (MuseumExhibit .objects .filter (sections__len = 10 ), [])
193
192
self .assertCountEqual (
0 commit comments