Skip to content

Commit 108d009

Browse files
committed
Move test to simplify diff
1 parent 1363717 commit 108d009

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed

tests/model_fields_/test_embedded_model.py

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -103,56 +103,6 @@ def test_pre_save(self):
103103
self.assertGreater(obj.data.auto_now, auto_now_two)
104104

105105

106-
class ArrayFieldTests(TestCase):
107-
@classmethod
108-
def setUpTestData(cls):
109-
cls.book = Book.objects.create(
110-
author=Author(
111-
name="Shakespeare",
112-
age=55,
113-
skills=["writing", "editing"],
114-
address=Address(city="NYC", state="NY", tags=["home", "shipping"]),
115-
),
116-
)
117-
118-
def test_contains(self):
119-
self.assertCountEqual(Book.objects.filter(author__skills__contains=["nonexistent"]), [])
120-
self.assertCountEqual(
121-
Book.objects.filter(author__skills__contains=["writing"]), [self.book]
122-
)
123-
# Nested
124-
self.assertCountEqual(
125-
Book.objects.filter(author__address__tags__contains=["nonexistent"]), []
126-
)
127-
self.assertCountEqual(
128-
Book.objects.filter(author__address__tags__contains=["home"]), [self.book]
129-
)
130-
131-
def test_contained_by(self):
132-
self.assertCountEqual(
133-
Book.objects.filter(author__skills__contained_by=["writing", "publishing"]), []
134-
)
135-
self.assertCountEqual(
136-
Book.objects.filter(author__skills__contained_by=["writing", "editing", "publishing"]),
137-
[self.book],
138-
)
139-
# Nested
140-
self.assertCountEqual(
141-
Book.objects.filter(author__address__tags__contained_by=["home", "work"]), []
142-
)
143-
self.assertCountEqual(
144-
Book.objects.filter(author__address__tags__contained_by=["home", "work", "shipping"]),
145-
[self.book],
146-
)
147-
148-
def test_len(self):
149-
self.assertCountEqual(Book.objects.filter(author__skills__len=1), [])
150-
self.assertCountEqual(Book.objects.filter(author__skills__len=2), [self.book])
151-
# Nested
152-
self.assertCountEqual(Book.objects.filter(author__address__tags__len=1), [])
153-
self.assertCountEqual(Book.objects.filter(author__address__tags__len=2), [self.book])
154-
155-
156106
class EmbeddedArrayTests(TestCase):
157107
def test_save_load(self):
158108
reviews = [
@@ -425,6 +375,56 @@ def test_nested(self):
425375
self.assertCountEqual(Book.objects.filter(author__address__city="NYC"), [obj])
426376

427377

378+
class ArrayFieldTests(TestCase):
379+
@classmethod
380+
def setUpTestData(cls):
381+
cls.book = Book.objects.create(
382+
author=Author(
383+
name="Shakespeare",
384+
age=55,
385+
skills=["writing", "editing"],
386+
address=Address(city="NYC", state="NY", tags=["home", "shipping"]),
387+
),
388+
)
389+
390+
def test_contains(self):
391+
self.assertCountEqual(Book.objects.filter(author__skills__contains=["nonexistent"]), [])
392+
self.assertCountEqual(
393+
Book.objects.filter(author__skills__contains=["writing"]), [self.book]
394+
)
395+
# Nested
396+
self.assertCountEqual(
397+
Book.objects.filter(author__address__tags__contains=["nonexistent"]), []
398+
)
399+
self.assertCountEqual(
400+
Book.objects.filter(author__address__tags__contains=["home"]), [self.book]
401+
)
402+
403+
def test_contained_by(self):
404+
self.assertCountEqual(
405+
Book.objects.filter(author__skills__contained_by=["writing", "publishing"]), []
406+
)
407+
self.assertCountEqual(
408+
Book.objects.filter(author__skills__contained_by=["writing", "editing", "publishing"]),
409+
[self.book],
410+
)
411+
# Nested
412+
self.assertCountEqual(
413+
Book.objects.filter(author__address__tags__contained_by=["home", "work"]), []
414+
)
415+
self.assertCountEqual(
416+
Book.objects.filter(author__address__tags__contained_by=["home", "work", "shipping"]),
417+
[self.book],
418+
)
419+
420+
def test_len(self):
421+
self.assertCountEqual(Book.objects.filter(author__skills__len=1), [])
422+
self.assertCountEqual(Book.objects.filter(author__skills__len=2), [self.book])
423+
# Nested
424+
self.assertCountEqual(Book.objects.filter(author__address__tags__len=1), [])
425+
self.assertCountEqual(Book.objects.filter(author__address__tags__len=2), [self.book])
426+
427+
428428
class InvalidLookupTests(SimpleTestCase):
429429
def test_invalid_field(self):
430430
msg = "Author has no field named 'first_name'"

0 commit comments

Comments
 (0)