From 4738b68a3b9f380035728d5b512d0be4e9120dae Mon Sep 17 00:00:00 2001 From: lizkrznarich Date: Fri, 13 Dec 2024 16:38:06 -0600 Subject: [PATCH] remove print statement, remove sorting for locations field and change heartbeat view to check for index instead of retrieving orgs --- rorapi/common/record_utils.py | 1 - rorapi/common/views.py | 8 +++++--- rorapi/tests/tests_integration/tests_v2.py | 6 ++---- rorapi/v2/models.py | 3 +-- rorapi/v2/record_constants.py | 1 - 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/rorapi/common/record_utils.py b/rorapi/common/record_utils.py index 3c3fc58..2332785 100644 --- a/rorapi/common/record_utils.py +++ b/rorapi/common/record_utils.py @@ -20,7 +20,6 @@ def get_lang_code(lang_string): def get_file_from_url(url): rsp = requests.get(url) rsp.raise_for_status() - print(rsp.json()) return rsp.json() def validate_record(data, schema): diff --git a/rorapi/common/views.py b/rorapi/common/views.py index e163012..ebcfa21 100644 --- a/rorapi/common/views.py +++ b/rorapi/common/views.py @@ -14,7 +14,7 @@ from rorapi.common.create_update import new_record_from_json, update_record_from_json from rorapi.common.csv_bulk import process_csv from rorapi.common.csv_utils import validate_csv -from rorapi.settings import REST_FRAMEWORK +from rorapi.settings import REST_FRAMEWORK, ES7, ES_VARS from rorapi.common.matching import match_organizations from rorapi.common.models import ( Errors @@ -175,8 +175,10 @@ class HeartbeatView(View): def get(self, request, version=REST_FRAMEWORK["DEFAULT_VERSION"]): print(version) try: - errors, organizations = search_organizations({}, version) - if errors is None: + index = ES_VARS['INDEX_V1'] + if version == 'v2': + index = ES_VARS['INDEX_V2'] + if ES7.indices.exists(index): return HttpResponse("OK") except: pass diff --git a/rorapi/tests/tests_integration/tests_v2.py b/rorapi/tests/tests_integration/tests_v2.py index 705488c..986a788 100644 --- a/rorapi/tests/tests_integration/tests_v2.py +++ b/rorapi/tests/tests_integration/tests_v2.py @@ -209,11 +209,9 @@ def verify_filtering(self, query): self.assertTrue(self.get_total(output) <= co_aggr['count']) for i in output['items']: self.assertTrue(t_aggr['title'] in i['types']) - self.assertEquals(c_aggr['id'].upper(), - i['locations'][0]['geonames_details']['country_code']) + self.assertTrue(c_aggr['id'].upper() in [l['geonames_details']['country_code'] for l in i['locations']]) self.assertTrue(s_aggr['title'] in i['status']) - self.assertEquals(co_aggr['id'].upper(), - i['locations'][0]['geonames_details']['continent_code']) + self.assertTrue(co_aggr['id'].upper() in [l['geonames_details']['continent_code'] for l in i['locations']]) self.assertTrue( any([t_aggr['id'] == t['id'] for t in output['meta']['types']])) diff --git a/rorapi/v2/models.py b/rorapi/v2/models.py index 4acfafe..e9c7d1a 100644 --- a/rorapi/v2/models.py +++ b/rorapi/v2/models.py @@ -93,8 +93,7 @@ def __init__(self, data): ] sorted_links = sorted(data.links, key=lambda x: x['type']) self.links = [Entity(l, ["value", "type"]) for l in sorted_links] - sorted_locations = sorted(data.locations, key=lambda x: x['geonames_id']) - self.locations = [Location(l) for l in sorted_locations] + self.locations = [Location(l) for l in data.locations] sorted_names = sorted(data.names, key=lambda x: x['value']) self.names = [Entity(n, ["value", "lang", "types"]) for n in sorted_names] sorted_rels = sorted(data.relationships, key=lambda x: x['type']) diff --git a/rorapi/v2/record_constants.py b/rorapi/v2/record_constants.py index 3f07d8a..63ef7bd 100644 --- a/rorapi/v2/record_constants.py +++ b/rorapi/v2/record_constants.py @@ -59,7 +59,6 @@ "domains": None, "external_ids": "type", "links": "type", - "locations": "geonames_id", "names": "value", "relationships": "type", "types": None