Skip to content

Commit

Permalink
test: Add test for extension codelists
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Dec 5, 2023
1 parent e87fcf3 commit c481de1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
4 changes: 1 addition & 3 deletions cove_ocds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ def explore_ocds(request, pk):
for path_string, codelist_info in context[key].items():
if codelist_info["codelist_url"].startswith(schema_ocds.codelists):
codelist_info["codelist_url"] = (
"https://standard.open-contracting.org/{}/en/schema/codelists/#".format(
db_data.data_schema_version
)
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()
)

Expand Down
37 changes: 32 additions & 5 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def test_get_json_data_missing_ids():


@pytest.mark.django_db
def test_codelist_url_rewriting(client):
def test_codelist_url_ocds_codelists(client):
file_name = os.path.join(
"tests",
"fixtures",
Expand All @@ -634,16 +634,43 @@ def test_codelist_url_rewriting(client):
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"].get("codelist_url")
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"].get(
"codelist_url"
)
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"
)

0 comments on commit c481de1

Please sign in to comment.