|
1 | 1 | import operator
|
2 |
| -from datetime import date, timedelta |
| 2 | +from datetime import timedelta |
3 | 3 |
|
4 | 4 | from django.core.exceptions import FieldDoesNotExist, ValidationError
|
5 | 5 | from django.db import models
|
|
19 | 19 |
|
20 | 20 | from .models import (
|
21 | 21 | Address,
|
22 |
| - ArtifactDetail, |
23 | 22 | Author,
|
24 | 23 | Book,
|
25 | 24 | Data,
|
26 |
| - ExhibitSection, |
27 | 25 | Holder,
|
28 | 26 | Library,
|
29 | 27 | Movie,
|
30 |
| - MuseumExhibit, |
31 | 28 | NestedData,
|
32 |
| - RestorationRecord, |
33 | 29 | Review,
|
34 | 30 | )
|
35 | 31 | from .utils import truncate_ms
|
@@ -125,165 +121,6 @@ def test_save_load_null(self):
|
125 | 121 | self.assertIsNone(movie.reviews)
|
126 | 122 |
|
127 | 123 |
|
128 |
| -class EmbeddedArrayQueryingTests(TestCase): |
129 |
| - @classmethod |
130 |
| - def setUpTestData(cls): |
131 |
| - reviews = [ |
132 |
| - Review(title="The best", rating=10), |
133 |
| - Review(title="Mediocre", rating=5), |
134 |
| - Review(title="Horrible", rating=1), |
135 |
| - ] |
136 |
| - cls.clouds = Movie.objects.create(title="Clouds", reviews=reviews) |
137 |
| - reviews = [ |
138 |
| - Review(title="Super", rating=9), |
139 |
| - Review(title="Meh", rating=5), |
140 |
| - Review(title="Horrible", rating=2), |
141 |
| - ] |
142 |
| - cls.frozen = Movie.objects.create(title="Frozen", reviews=reviews) |
143 |
| - reviews = [ |
144 |
| - Review(title="Excellent", rating=9), |
145 |
| - Review(title="Wow", rating=8), |
146 |
| - Review(title="Classic", rating=7), |
147 |
| - ] |
148 |
| - cls.bears = Movie.objects.create(title="Bears", reviews=reviews) |
149 |
| - cls.egypt = MuseumExhibit.objects.create( |
150 |
| - exhibit_name="Ancient Egypt", |
151 |
| - sections=[ |
152 |
| - ExhibitSection( |
153 |
| - section_number=1, |
154 |
| - artifacts=[ |
155 |
| - ArtifactDetail( |
156 |
| - name="Ptolemaic Crown", |
157 |
| - description="Royal headpiece worn by Ptolemy kings.", |
158 |
| - metadata={ |
159 |
| - "material": "gold", |
160 |
| - "origin": "Egypt", |
161 |
| - "era": "Ptolemaic Period", |
162 |
| - }, |
163 |
| - ) |
164 |
| - ], |
165 |
| - ) |
166 |
| - ], |
167 |
| - ) |
168 |
| - cls.wonders = MuseumExhibit.objects.create( |
169 |
| - exhibit_name="Wonders of the Ancient World", |
170 |
| - sections=[ |
171 |
| - ExhibitSection( |
172 |
| - section_number=1, |
173 |
| - artifacts=[ |
174 |
| - ArtifactDetail( |
175 |
| - name="Statue of Zeus", |
176 |
| - description="One of the Seven Wonders, created by Phidias.", |
177 |
| - metadata={"location": "Olympia", "height_m": 12}, |
178 |
| - ), |
179 |
| - ArtifactDetail( |
180 |
| - name="Hanging Gardens", |
181 |
| - description="Legendary gardens of Babylon.", |
182 |
| - metadata={"debated_existence": True}, |
183 |
| - ), |
184 |
| - ], |
185 |
| - ), |
186 |
| - ExhibitSection( |
187 |
| - section_number=2, |
188 |
| - artifacts=[ |
189 |
| - ArtifactDetail( |
190 |
| - name="Lighthouse of Alexandria", |
191 |
| - description="Guided sailors safely to port.", |
192 |
| - metadata={"height_m": 100, "built": "3rd century BC"}, |
193 |
| - ) |
194 |
| - ], |
195 |
| - ), |
196 |
| - ], |
197 |
| - ) |
198 |
| - cls.new_descoveries = MuseumExhibit.objects.create( |
199 |
| - exhibit_name="New Discoveries", |
200 |
| - sections=[ExhibitSection(section_number=1, artifacts=[])], |
201 |
| - ) |
202 |
| - cls.lost_empires = MuseumExhibit.objects.create( |
203 |
| - exhibit_name="Lost Empires", |
204 |
| - main_section=ExhibitSection( |
205 |
| - section_number=3, |
206 |
| - artifacts=[ |
207 |
| - ArtifactDetail( |
208 |
| - name="Bronze Statue", |
209 |
| - description="Statue from the Hellenistic period.", |
210 |
| - metadata={"origin": "Pergamon", "material": "bronze"}, |
211 |
| - restorations=[ |
212 |
| - RestorationRecord( |
213 |
| - date=date(1998, 4, 15), |
214 |
| - description="Removed oxidized layer.", |
215 |
| - restored_by="Restoration Lab A", |
216 |
| - ), |
217 |
| - RestorationRecord( |
218 |
| - date=date(2010, 7, 22), |
219 |
| - description="Reinforced the base structure.", |
220 |
| - restored_by="Dr. Liu Cheng", |
221 |
| - ), |
222 |
| - ], |
223 |
| - last_restoration=RestorationRecord( |
224 |
| - date=date(2010, 7, 22), |
225 |
| - description="Reinforced the base structure.", |
226 |
| - restored_by="Dr. Liu Cheng", |
227 |
| - ), |
228 |
| - ) |
229 |
| - ], |
230 |
| - ), |
231 |
| - ) |
232 |
| - |
233 |
| - def test_filter_with_field(self): |
234 |
| - self.assertCountEqual( |
235 |
| - Movie.objects.filter(reviews__title="Horrible"), [self.clouds, self.frozen] |
236 |
| - ) |
237 |
| - |
238 |
| - def test_filter_with_embeddedfield_path(self): |
239 |
| - self.assertCountEqual( |
240 |
| - MuseumExhibit.objects.filter(sections__0__section_number=1), |
241 |
| - [self.egypt, self.wonders, self.new_descoveries], |
242 |
| - ) |
243 |
| - |
244 |
| - def test_filter_with_embeddedfield_array_path(self): |
245 |
| - self.assertCountEqual( |
246 |
| - MuseumExhibit.objects.filter( |
247 |
| - main_section__artifacts__restorations__0__restored_by="Restoration Lab A" |
248 |
| - ), |
249 |
| - [self.lost_empires], |
250 |
| - ) |
251 |
| - |
252 |
| - def test_len(self): |
253 |
| - self.assertCountEqual(MuseumExhibit.objects.filter(sections__len=10), []) |
254 |
| - self.assertCountEqual( |
255 |
| - MuseumExhibit.objects.filter(sections__len=1), [self.egypt, self.new_descoveries] |
256 |
| - ) |
257 |
| - # Nested EMF |
258 |
| - self.assertCountEqual( |
259 |
| - MuseumExhibit.objects.filter(main_section__artifacts__len=1), [self.lost_empires] |
260 |
| - ) |
261 |
| - self.assertCountEqual(MuseumExhibit.objects.filter(main_section__artifacts__len=2), []) |
262 |
| - self.assertCountEqual(MuseumExhibit.objects.filter(main_section__artifacts__len=2), []) |
263 |
| - # Nested Indexed Array |
264 |
| - self.assertCountEqual( |
265 |
| - MuseumExhibit.objects.filter(sections__0__artifacts__len=2), [self.wonders] |
266 |
| - ) |
267 |
| - self.assertCountEqual( |
268 |
| - MuseumExhibit.objects.filter(sections__0__artifacts__len=0), [self.new_descoveries] |
269 |
| - ) |
270 |
| - self.assertCountEqual( |
271 |
| - MuseumExhibit.objects.filter(sections__1__artifacts__len=1), [self.wonders] |
272 |
| - ) |
273 |
| - |
274 |
| - def test_overlap_simplefield(self): |
275 |
| - self.assertSequenceEqual( |
276 |
| - MuseumExhibit.objects.filter(sections__section_number__overlap=[10]), [] |
277 |
| - ) |
278 |
| - self.assertSequenceEqual( |
279 |
| - MuseumExhibit.objects.filter(sections__section_number__overlap=[1]), |
280 |
| - [self.egypt, self.wonders, self.new_descoveries], |
281 |
| - ) |
282 |
| - self.assertSequenceEqual( |
283 |
| - MuseumExhibit.objects.filter(sections__section_number__overlap=[2]), [self.wonders] |
284 |
| - ) |
285 |
| - |
286 |
| - |
287 | 124 | class QueryingTests(TestCase):
|
288 | 125 | @classmethod
|
289 | 126 | def setUpTestData(cls):
|
|
0 commit comments