summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-10-14 18:56:53 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:20:59 +0100
commit6fc6efad0ee57e430903b0d24c6e925652ff3714 (patch)
tree9fb7a25cc7bb7c210cbd71c97e8f99e2d55e8f67 /archaeological_operations
parentba24111f03c601458f2ede5447c57fc7b22e6246 (diff)
downloadIshtar-6fc6efad0ee57e430903b0d24c6e925652ff3714.tar.bz2
Ishtar-6fc6efad0ee57e430903b0d24c6e925652ff3714.zip
Syndication - search limitation; API to send available types
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/tests.py84
-rw-r--r--archaeological_operations/urls.py4
-rw-r--r--archaeological_operations/views_api.py8
3 files changed, 71 insertions, 25 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
diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py
index 4aee195f4..a7b41ff15 100644
--- a/archaeological_operations/urls.py
+++ b/archaeological_operations/urls.py
@@ -361,4 +361,8 @@ urlpatterns = [
r"api/search/operation/$", views_api.SearchOperationAPI.as_view(),
name="api-search-operation"
),
+ url(
+ r"api/facets/operation/$", views_api.FacetOperationAPIView.as_view(),
+ name="api-facets-operation"
+ ),
]
diff --git a/archaeological_operations/views_api.py b/archaeological_operations/views_api.py
index 48127ec4b..aca400ea3 100644
--- a/archaeological_operations/views_api.py
+++ b/archaeological_operations/views_api.py
@@ -1,7 +1,11 @@
-from ishtar_common.rest import SearchAPIView
-from archaeological_operations import models
+from ishtar_common.rest import SearchAPIView, FacetAPIView
+from archaeological_operations import models, forms
class SearchOperationAPI(SearchAPIView):
model = models.Operation
+
+class FacetOperationAPIView(FacetAPIView):
+ models = [models.Operation, models.ArchaeologicalSite]
+ select_forms = [forms.OperationSelect, forms.SiteSelect]