diff --git a/cove_ocds/views.py b/cove_ocds/views.py index 11b5ea74..9d5e0488 100644 --- a/cove_ocds/views.py +++ b/cove_ocds/views.py @@ -242,6 +242,14 @@ def explore_ocds(request, pk): } ) + for key in ("additional_closed_codelist_values", "additional_open_codelist_values"): + for path_string, codelist_info in context[key].items(): + if codelist_info["codelist_url"].startswith(schema_ocds.codelists): + codelist_info["codelist_url"] = ( + f"https://standard.open-contracting.org/{db_data.data_schema_version}/en/schema/codelists/#" + + re.sub(r"([A-Z])", r"-\1", codelist_info["codelist"].split(".")[0]).lower() + ) + schema_version = getattr(schema_ocds, "version", None) if schema_version: db_data.schema_version = schema_version diff --git a/requirements.txt b/requirements.txt index e5c26198..e469b096 100644 --- a/requirements.txt +++ b/requirements.txt @@ -44,8 +44,6 @@ django-bootstrap3==15.0.0 # via # -r requirements.in # libcoveweb -django-environ==0.4.5 - # via libcoveweb et-xmlfile==1.1.0 # via openpyxl exceptiongroup==1.1.3 @@ -79,7 +77,7 @@ libcove[flatten] @ https://github.com/jpmckinney/lib-cove/archive/hotfix2.zip # libcoveweb libcoveocds[perf,web]==0.12.7 # via -r requirements.in -libcoveweb==0.28.0 +libcoveweb==0.30.0 # via -r requirements.in lxml==4.9.1 # via flattentool diff --git a/requirements_dev.txt b/requirements_dev.txt index b08f816f..0eae023c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -81,10 +81,6 @@ django-bootstrap3==15.0.0 # via # -r requirements.txt # libcoveweb -django-environ==0.4.5 - # via - # -r requirements.txt - # libcoveweb docopt==0.6.2 # via coveralls et-xmlfile==1.1.0 @@ -151,7 +147,7 @@ libcoveocds[perf,web]==0.12.7 # via # -r requirements.txt # libcoveocds -libcoveweb==0.28.0 +libcoveweb==0.30.0 # via -r requirements.txt libsass==0.20.1 # via -r requirements_dev.in diff --git a/tests/test_general.py b/tests/test_general.py index 8d076ccf..131eb537 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -619,3 +619,58 @@ def test_get_json_data_missing_ids(): missin_ids_paths = cove_common.get_json_data_missing_ids(user_data_paths, schema_obj) assert missin_ids_paths == results + + +@pytest.mark.django_db +def test_codelist_url_ocds_codelists(client): + file_name = os.path.join( + "tests", + "fixtures", + "tenders_releases_2_releases_codelists.json", + ) + with open(os.path.join(file_name)) as fp: + user_data = fp.read() + data = SuppliedData.objects.create() + data.original_file.save("test.json", ContentFile(user_data)) + data.current_app = "cove_ocds" + resp = client.get(data.get_absolute_url()) + + assert resp.status_code == 200 + assert len(resp.context["additional_closed_codelist_values"]) == 1 + assert ( + resp.context["additional_closed_codelist_values"]["releases/tag"]["codelist_url"] + == "https://standard.open-contracting.org/1.1/en/schema/codelists/#release-tag" + ) + assert len(resp.context["additional_open_codelist_values"]) == 1 + assert ( + resp.context["additional_open_codelist_values"]["releases/tender/items/classification/scheme"]["codelist_url"] + == "https://standard.open-contracting.org/1.1/en/schema/codelists/#item-classification-scheme" + ) + + +@pytest.mark.django_db +def test_codelist_url_extension_codelists(client): + file_name = os.path.join( + "tests", + "fixtures", + "tenders_releases_1_release_with_various_codelists.json", + ) + with open(os.path.join(file_name)) as fp: + user_data = fp.read() + data = SuppliedData.objects.create() + data.original_file.save("test.json", ContentFile(user_data)) + data.current_app = "cove_ocds" + resp = client.get(data.get_absolute_url()) + + assert resp.status_code == 200 + assert len(resp.context["additional_closed_codelist_values"]) == 1 + assert ( + resp.context["additional_closed_codelist_values"]["releases/contracts/tariffs/paidBy"]["codelist_url"] + == "http://standard.open-contracting.org/profiles/ppp/latest/es/codelists/chargePaidBy.csv" + ) + # lib-cove-web displays codelist_amend_urls separately. + assert len(resp.context["additional_open_codelist_values"]) == 1 + assert ( + resp.context["additional_open_codelist_values"]["releases/tender/documents/documentType"]["codelist_url"] + == "https://standard.open-contracting.org/1.1/en/schema/codelists/#document-type" + )