Skip to content

Commit

Permalink
Merge pull request #192 from odscjames/2023-12-01
Browse files Browse the repository at this point in the history
Links to codelists - rewrite to OCDS Standard. & Upgrade lib-cove-web
  • Loading branch information
jpmckinney authored Dec 5, 2023
2 parents 15cfe26 + c481de1 commit 2639a24
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
8 changes: 8 additions & 0 deletions cove_ocds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 2639a24

Please sign in to comment.