Skip to content

Commit 394970a

Browse files
committed
should_index: test for exception on field/property
1 parent c833a40 commit 394970a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

tests/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Example(models.Model):
77
address = models.CharField(max_length=200)
88
lat = models.FloatField()
99
lng = models.FloatField()
10+
is_admin = models.BooleanField(default=False)
1011
category = []
1112
locations = []
1213
index_me = True
@@ -27,3 +28,7 @@ def static_should_index():
2728
@staticmethod
2829
def static_should_not_index():
2930
return False
31+
32+
@property
33+
def property_should_index(self):
34+
return True

tests/test_index.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,18 @@ class ExampleIndex(AlgoliaIndex):
213213
instance_should_not.index_me = False
214214
obj = index._build_object(instance_should_not)
215215
self.assertFalse(index._should_index(instance_should_not),
216-
"We should not index an instance when its should_index attr is False")
216+
"We should not index an instance when its should_index attr is False")
217+
218+
def test_should_index_field_raises(self):
219+
class ExampleIndex(AlgoliaIndex):
220+
fields = 'name'
221+
should_index = 'is_admin'
222+
with self.assertRaises(AlgoliaIndexError):
223+
index = ExampleIndex(Example, self.client)
224+
225+
def test_should_index_property_raises(self):
226+
class ExampleIndex(AlgoliaIndex):
227+
fields = 'name'
228+
should_index = 'property_should_index'
229+
with self.assertRaises(AlgoliaIndexError):
230+
index = ExampleIndex(Example, self.client)

0 commit comments

Comments
 (0)