fix: use stable search catalog codes
This commit is contained in:
@@ -4,7 +4,7 @@ import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from search.api import Api, ApiError, catalog_code
|
||||
from search.api import Api, ApiError
|
||||
|
||||
|
||||
class SearchApiTest(unittest.TestCase):
|
||||
@@ -27,12 +27,12 @@ class SearchApiTest(unittest.TestCase):
|
||||
api = self.make_api(Path(temporary))
|
||||
response = {"hits": {"hits": [{"_source": {"document_code": "7", "edition_code": "10", "document_name_ru": "Закон"}, "highlight": {"text_ru": ["<em>Закон</em>"]}}]}}
|
||||
with patch("search.api.request_json", return_value=response) as request:
|
||||
status, payload = api.handle("GET", f"/search?q=%D0%B7%D0%B0%D0%BA%D0%BE%D0%BD&language=ru&page=2&page_size=5&status={catalog_code('status', ('Действует', 'Күчүндө'))}")
|
||||
status, payload = api.handle("GET", "/search?q=%D0%B7%D0%B0%D0%BA%D0%BE%D0%BD&language=ru&page=2&page_size=5&status=active")
|
||||
self.assertEqual(status, 200)
|
||||
self.assertEqual(payload["results"][0]["snippet"], "<em>Закон</em>")
|
||||
body = json.loads(request.call_args.args[2])
|
||||
self.assertEqual((body["from"], body["size"]), (5, 6))
|
||||
self.assertIn({"term": {"status_ru": "Действует"}}, body["query"]["bool"]["filter"])
|
||||
self.assertIn({"term": {"status_code": "active"}}, body["query"]["bool"]["filter"])
|
||||
with self.assertRaisesRegex(ApiError, "within 10000 results"):
|
||||
api.handle("GET", "/search?q=x&page=100&page_size=100")
|
||||
|
||||
@@ -55,12 +55,12 @@ class SearchApiTest(unittest.TestCase):
|
||||
def test_filters_count_documents_and_return_bilingual_labels(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
api = self.make_api(Path(temporary))
|
||||
response = {"aggregations": {name: {"buckets": [{"key": ["Закон", "Мыйзам"], "documents": {"value": 3}}]} for name in ("document_types", "statuses", "authorities")}}
|
||||
response = {"aggregations": {name: {"buckets": [{"key": "law" if name == "document_types" else "active" if name == "statuses" else "parliament", "documents": {"value": 3}}]} for name in ("document_types", "statuses", "authorities")}}
|
||||
with patch("search.api.request_json", return_value=response) as request:
|
||||
payload = api.handle("GET", "/search/filters?language=ky")[1]
|
||||
self.assertEqual(payload["document_types"][0], {"code": catalog_code("document_type", ("Закон", "Мыйзам")), "labels": {"ru": "Закон", "ky": "Мыйзам"}, "count": 3})
|
||||
self.assertEqual(payload["document_types"][0], {"code": "law", "labels": {"ru": "Закон", "ky": "Мыйзам"}, "count": 3})
|
||||
body = json.loads(request.call_args.args[2])
|
||||
self.assertIn("multi_terms", body["aggs"]["document_types"])
|
||||
self.assertIn("terms", body["aggs"]["document_types"])
|
||||
self.assertEqual(body["query"], {"term": {"is_current_edition": True}})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user