summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py84
1 files changed, 61 insertions, 23 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index cd1f6ac6d..d13a21011 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -4452,15 +4452,17 @@ class ApiTest(OperationInitTest, APITestCase):
self.auth_token = "Token " + Token.objects.create(user=self.user).key
self.api_user = ApiUser.objects.create(user_ptr=self.user, ip="127.0.0.1")
- def create_api_search_model(self):
+ def create_api_search_model(self, app_label="archaeological_operations",
+ model="operation"):
return ApiSearchModel.objects.create(
user=self.api_user,
content_type=ContentType.objects.get(
- app_label="archaeological_operations",
- model="operation"
- ))
+ app_label=app_label, model=model
+ ),
+ )
def test_api_permissions(self):
+ # POV: external
url = reverse("api-search-operation")
response = self.client.get(url, format="json")
# nothing OK
@@ -4473,9 +4475,8 @@ class ApiTest(OperationInitTest, APITestCase):
api_search_model = self.create_api_search_model()
content_type_id = api_search_model.content_type.id
api_search_model.content_type = ContentType.objects.get(
- app_label="archaeological_operations",
- model="archaeologicalsite"
- )
+ app_label="archaeological_operations", model="archaeologicalsite"
+ )
api_search_model.save()
# token + IP + bad model
response = self.client.get(
@@ -4500,48 +4501,85 @@ class ApiTest(OperationInitTest, APITestCase):
self.api_user.save()
def test_api_search(self):
+ # POV: external
api_search_model = self.create_api_search_model()
url = reverse("api-search-operation")
- data = {
- "submited": 1,
- "search_vector": "28"
- }
+ data = {"submited": 1, "search_vector": "28"}
response = self.client.get(
- url, format="json", HTTP_AUTHORIZATION=self.auth_token,
- data=data
+ url, format="json", HTTP_AUTHORIZATION=self.auth_token, data=data
)
self.assertEqual(response.status_code, 200)
j = json.loads(response.content.decode())
- self.assertEqual(j['recordsTotal'], 2)
+ self.assertEqual(j["recordsTotal"], 2)
# test default filter
search_code_q = str(pgettext("key for text search", "patriarche"))
api_search_model.limit_query = '{}="28124"'.format(search_code_q)
api_search_model.save()
response = self.client.get(
+ url, format="json", HTTP_AUTHORIZATION=self.auth_token, data=data
+ )
+ self.assertEqual(response.status_code, 200)
+ j = json.loads(response.content.decode())
+ self.assertEqual(j["recordsTotal"], 1, "api search limitation not effective")
+
+ def test_type_match_api(self):
+ # POV: external
+ # return export of tables
+ random_operation_type = models.OperationType.objects.all()[0]
+ random_operation_type.available = False
+ random_operation_type.save()
+ self.create_api_search_model()
+ url = reverse("api-facets-operation")
+ response = self.client.get(
+ url, format="json", HTTP_AUTHORIZATION=self.auth_token,
+ )
+ self.assertEqual(response.status_code, 200)
+ j = json.loads(response.content.decode())
+ self.assertIn('archaeological_operations.operation', j)
+ # no permissions for archaeological_site
+ self.assertNotIn('archaeological_operations.archaeological_site', j)
+
+ has_type = False
+ for content in j['archaeological_operations.operation']:
+ if content[0] == ["type", "type"]:
+ has_type = True
+ lst = content[1]
+ for tpe in models.OperationType.objects.filter(available=True).all():
+ self.assertIn([tpe.txt_idx, tpe.label], lst)
+ # do not send not available
+ for tpe in models.OperationType.objects.filter(available=False).all():
+ self.assertNotIn([tpe.txt_idx, tpe.label], lst)
+ break
+ self.assertTrue(has_type)
+
+ self.create_api_search_model(app_label="archaeological_operations",
+ model="archaeologicalsite")
+ url = reverse("api-facets-operation")
+ response = self.client.get(
url, format="json", HTTP_AUTHORIZATION=self.auth_token,
- data=data
)
self.assertEqual(response.status_code, 200)
j = json.loads(response.content.decode())
- self.assertEqual(j['recordsTotal'], 1, "api search limitation not effective")
+ self.assertIn('archaeological_operations.archaeologicalsite', j)
+ def test_type_admin(self):
+ # POV: local
+ # create and update matches from an external source
+ # delete old matches!
+ pass
def test_query_transformation(self):
+ # POV: local
# change query terms from a source Ishtar to match distant Ishtar
pass
def test_external_source_query(self):
+ # POV: local
# send a query to an external source when activated
- # test permissions for this query
+ # test permissions for this query (external source only allowed to a subset of users)
# test timeout
pass
- def test_type_match_api(self):
- pass
-
- def test_type_admin(self):
- pass
-
def test_distant_sheet_display(self):
# test query limitation
pass