Skip to content

Commit 4e85fc1

Browse files
committed
Revert: Restore accidentally removed tests from f109cf5.
1 parent 2b5b287 commit 4e85fc1

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
@@ -126,12 +126,14 @@ class Address(EmbeddedModel):
126126
city = models.CharField(max_length=20)
127127
state = models.CharField(max_length=2)
128128
zip_code = models.IntegerField(db_index=True)
129+
tags = ArrayField(models.CharField(max_length=100), null=True, blank=True)
129130

130131

131132
class Author(EmbeddedModel):
132133
name = models.CharField(max_length=10)
133134
age = models.IntegerField()
134135
address = EmbeddedModelField(Address)
136+
skills = ArrayField(models.CharField(max_length=100), null=True, blank=True)
135137

136138

137139
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
@@ -102,6 +102,56 @@ def test_pre_save(self):
102102
self.assertGreater(obj.data.auto_now, auto_now_two)
103103

104104

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

0 commit comments

Comments
 (0)