summaryrefslogtreecommitdiff
path: root/archaeological_context_records/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records/tests.py')
-rw-r--r--archaeological_context_records/tests.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index 89b15fbbf..b0f4b8f9e 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -273,6 +273,20 @@ class ContextRecordTest(ContextRecordInit, TestCase):
cr.operation
)
+ def test_search_vector_update(self):
+ cr = self.create_context_record(force=True)[0]
+ cr = models.ContextRecord.objects.get(pk=cr.pk)
+ cr.label = "Label label"
+ cr.location = "I am heeere"
+ cr.save()
+ for key in ('label', 'heeer'):
+ self.assertIn(key, cr.search_vector)
+ cr.operation.code_patriarche = "PATRIARCHE"
+ cr.operation.save()
+ cr = models.ContextRecord.objects.get(pk=cr.pk)
+ self.assertIn(settings.ISHTAR_OPE_PREFIX.lower() + "patriarch",
+ cr.search_vector)
+
def test_upstream_cache_update(self):
cr = self.create_context_record()[0]
cr_pk = cr.pk
@@ -399,6 +413,44 @@ class ContextRecordSearchTest(ContextRecordInit, TestCase):
models.RecordRelations.objects.create(
left_record=cr_1, right_record=cr_2, relation_type=sym_rel_type)
+ def test_town_search(self):
+ c = Client()
+ c.login(username=self.username, password=self.password)
+
+ data = {'numero_insee': '98989', 'name': 'base_town'}
+ base_town = self.create_towns(datas=data)[-1]
+
+ parcel = self.create_parcel(data={'town': base_town,
+ 'section': 'A', 'parcel_number': '1'})[-1]
+ self.context_records[0].parcel = parcel
+ self.context_records[0].save()
+
+ data = {'numero_insee': '56789', 'name': 'parent_town'}
+ parent_town = self.create_towns(datas=data)[-1]
+ parent_town.children.add(base_town)
+
+ data = {'numero_insee': '01234', 'name': 'child_town'}
+ child_town = self.create_towns(datas=data)[-1]
+ base_town.children.add(child_town)
+
+ # simple search
+ search = {'parcel__town': base_town.pk}
+ response = c.get(reverse('get-contextrecord'), search)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(json.loads(response.content)['total'], 1)
+
+ # parent search
+ search = {'parcel__town': parent_town.pk}
+ response = c.get(reverse('get-contextrecord'), search)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(json.loads(response.content)['total'], 1)
+
+ # child search
+ search = {'parcel__town': child_town.pk}
+ response = c.get(reverse('get-contextrecord'), search)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(json.loads(response.content)['total'], 1)
+
def testSearchExport(self):
c = Client()
response = c.get(reverse('get-contextrecord'))
@@ -416,6 +468,14 @@ class ContextRecordSearchTest(ContextRecordInit, TestCase):
{'label': 'cr 1',
'cr_relation_types_0': self.cr_rel_type.pk})
self.assertEqual(json.loads(response.content)['total'], 2)
+ # test search vector
+ response = c.get(reverse('get-contextrecord'),
+ {'search_vector': 'CR'})
+ self.assertEqual(json.loads(response.content)['total'], 2)
+ # the 2 context records have the same operation
+ response = c.get(reverse('get-contextrecord'),
+ {'search_vector': 'op2010'})
+ self.assertEqual(json.loads(response.content)['total'], 2)
# test search between related operations
first_ope = self.operations[0]
first_ope.year = 2010