Skip to content

Commit 3d354c8

Browse files
committed
Revert: Restore accidentally removed tests from f109cf5.
1 parent 5702778 commit 3d354c8

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
@@ -115,12 +115,14 @@ class Address(EmbeddedModel):
115115
city = models.CharField(max_length=20)
116116
state = models.CharField(max_length=2)
117117
zip_code = models.IntegerField(db_index=True)
118+
tags = ArrayField(models.CharField(max_length=100), null=True, blank=True)
118119

119120

120121
class Author(EmbeddedModel):
121122
name = models.CharField(max_length=10)
122123
age = models.IntegerField()
123124
address = EmbeddedModelField(Address)
125+
skills = ArrayField(models.CharField(max_length=100), null=True, blank=True)
124126

125127

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

103103

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

0 commit comments

Comments
 (0)