Skip to content

Commit 98d7f68

Browse files
committed
Revert: Restore accidentally removed tests from f109cf5.
1 parent 5e1be5d commit 98d7f68

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tests/model_fields_/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,14 @@ class Address(EmbeddedModel):
121121
city = models.CharField(max_length=20)
122122
state = models.CharField(max_length=2)
123123
zip_code = models.IntegerField(db_index=True)
124+
tags = ArrayField(models.CharField(max_length=100), null=True, blank=True)
124125

125126

126127
class Author(EmbeddedModel):
127128
name = models.CharField(max_length=10)
128129
age = models.IntegerField()
129130
address = EmbeddedModelField(Address)
131+
skills = ArrayField(models.CharField(max_length=100), null=True, blank=True)
130132

131133

132134
class Book(models.Model):

tests/model_fields_/test_embedded_model.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,56 @@ 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+
106156
class EmbeddedArrayTests(TestCase):
107157
def test_save_load(self):
108158
reviews = [

0 commit comments

Comments
 (0)