Skip to content

Commit

Permalink
HDXDSYS-1016 Fix resource ordering (#74)
Browse files Browse the repository at this point in the history
* Fix resource ordering issue
Try catch for CKAN test
Update pre-commit

* Reset valid locations for test

* Update HDX Python Country
  • Loading branch information
mcarans authored Sep 6, 2024
1 parent 671c5e1 commit 8d0f5f1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .config/pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: end-of-file-fixer
- id: check-ast
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.1
rev: v0.6.4
hooks:
# Run the linter.
- id: ruff
Expand All @@ -17,7 +17,7 @@ repos:
- id: ruff-format
args: [--config, .config/ruff.toml]
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.2.13
rev: 0.4.5
hooks:
# Run the pip compile
- id: pip-compile
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ dependencies = [
"ckanapi>=4.8",
"defopt>=6.4.0",
"email_validator",
"hdx-python-country>=3.7.7",
"hdx-python-utilities>=3.7.2",
"hdx-python-country>=3.7.8",
"hdx-python-utilities>=3.7.3",
"libhxl>=5.2.1",
"makefun",
"ndg-httpsclient",
Expand Down
50 changes: 27 additions & 23 deletions requirements.txt
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
# uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt
annotated-types==0.7.0
# via pydantic
attrs==23.2.0
attrs==24.2.0
# via
# frictionless
# jsonlines
# jsonschema
# referencing
cachetools==5.4.0
cachetools==5.5.0
# via google-auth
certifi==2024.7.4
certifi==2024.8.30
# via requests
cffi==1.16.0
cffi==1.17.1
# via cryptography
cfgv==3.4.0
# via pre-commit
Expand All @@ -24,9 +24,9 @@ ckanapi==4.8
# via hdx-python-api (pyproject.toml)
click==8.1.7
# via typer
coverage==7.6.0
coverage==7.6.1
# via pytest-cov
cryptography==43.0.0
cryptography==43.0.1
# via pyopenssl
defopt==6.4.0
# via hdx-python-api (pyproject.toml)
Expand All @@ -46,27 +46,27 @@ et-xmlfile==1.1.0
# via openpyxl
filelock==3.15.4
# via virtualenv
frictionless==5.17.0
frictionless==5.17.1
# via hdx-python-utilities
google-auth==2.32.0
google-auth==2.34.0
# via
# google-auth-oauthlib
# gspread
google-auth-oauthlib==1.2.1
# via gspread
gspread==6.1.2
# via hdx-python-api (pyproject.toml)
hdx-python-country==3.7.7
hdx-python-country==3.7.8
# via hdx-python-api (pyproject.toml)
hdx-python-utilities==3.7.2
hdx-python-utilities==3.7.3
# via
# hdx-python-api (pyproject.toml)
# hdx-python-country
humanize==4.10.0
# via frictionless
identify==2.6.0
# via pre-commit
idna==3.7
idna==3.8
# via
# email-validator
# requests
Expand Down Expand Up @@ -106,7 +106,7 @@ markupsafe==2.1.5
# via jinja2
mdurl==0.1.2
# via markdown-it-py
more-itertools==10.3.0
more-itertools==10.5.0
# via inflect
ndg-httpsclient==0.5.1
# via hdx-python-api (pyproject.toml)
Expand All @@ -132,7 +132,7 @@ ply==3.11
# libhxl
pockets==0.9.1
# via sphinxcontrib-napoleon
pre-commit==3.7.1
pre-commit==3.8.0
# via hdx-python-api (pyproject.toml)
pyasn1==0.6.0
# via
Expand All @@ -144,9 +144,9 @@ pyasn1-modules==0.4.0
# via google-auth
pycparser==2.22
# via cffi
pydantic==2.8.2
pydantic==2.9.0
# via frictionless
pydantic-core==2.20.1
pydantic-core==2.23.2
# via pydantic
pygments==2.18.0
# via rich
Expand All @@ -173,7 +173,7 @@ python-slugify==8.0.4
# via
# ckanapi
# frictionless
pyyaml==6.0.1
pyyaml==6.0.2
# via
# frictionless
# pre-commit
Expand All @@ -200,9 +200,9 @@ requests-oauthlib==2.0.0
# via google-auth-oauthlib
rfc3986==2.0.0
# via frictionless
rich==13.7.1
rich==13.8.0
# via typer
rpds-py==0.19.1
rpds-py==0.20.0
# via
# jsonschema
# referencing
Expand All @@ -212,13 +212,13 @@ ruamel-yaml==0.18.6
# via hdx-python-utilities
ruamel-yaml-clib==0.2.8
# via ruamel-yaml
setuptools==71.1.0
setuptools==74.1.2
# via ckanapi
shellingham==1.5.4
# via typer
simpleeval==0.9.13
# via frictionless
simplejson==3.19.2
simplejson==3.19.3
# via ckanapi
six==1.16.0
# via
Expand All @@ -241,7 +241,7 @@ text-unidecode==1.3
# via python-slugify
typeguard==4.3.0
# via inflect
typer==0.12.3
typer==0.12.5
# via frictionless
typing-extensions==4.12.2
# via
Expand All @@ -250,6 +250,8 @@ typing-extensions==4.12.2
# pydantic-core
# typeguard
# typer
tzdata==2024.1
# via pydantic
unidecode==1.3.8
# via
# libhxl
Expand All @@ -258,16 +260,18 @@ urllib3==2.2.2
# via
# libhxl
# requests
validators==0.33.0
validators==0.34.0
# via frictionless
virtualenv==20.26.3
# via pre-commit
wheel==0.43.0
wheel==0.44.0
# via libhxl
xlrd==2.0.1
# via hdx-python-utilities
xlrd3==1.1.0
# via libhxl
xlsx2csv==0.8.3
# via hdx-python-utilities
xlsxwriter==3.2.0
# via tableschema-to-template
xlwt==1.3.0
Expand Down
3 changes: 2 additions & 1 deletion src/hdx/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,8 @@ def _dataset_update_resources(
resources_to_delete = list(reversed(resources_to_delete))
if match_resource_order:
new_resource_order = [
(x["name"], x["format"]) for x in resources_metadata_to_update
(x["name"], x["format"].lower())
for x in resources_metadata_to_update
]
else:
new_resource_order = None
Expand Down
39 changes: 22 additions & 17 deletions tests/hdx/api/test_ckan.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from gspread.urls import DRIVE_FILES_API_V3_URL

from hdx.api.configuration import Configuration
from hdx.api.locations import Locations
from hdx.data.dataset import Dataset
from hdx.data.resource import Resource
from hdx.data.vocabulary import Vocabulary
Expand All @@ -33,6 +34,7 @@ def configuration(self):
user_agent="test",
hdx_key=hdx_key,
)
Locations._validlocations = None
Country.countriesdata(use_live=False)

@pytest.fixture(scope="function")
Expand Down Expand Up @@ -74,23 +76,26 @@ def gclient(self):

@pytest.fixture(scope="function")
def setup_teardown_folder(self, configuration, gclient, params):
payload = {
"name": "hdx_python_api_test_tmp",
"mimeType": "application/vnd.google-apps.folder",
"parents": ["1dvx0H0RG5ZfM9QL148uymWpbuxAqmOzD"],
}
r = gclient.http_client.request(
"post", DRIVE_FILES_API_V3_URL, json=payload, params=params
)
folderid = r.json()["id"]
yield gclient, folderid

payload = {"trashed": True}
url = f"{DRIVE_FILES_API_V3_URL}/{folderid}"
gclient.http_client.request("patch", url, json=payload, params=params)
Vocabulary._approved_vocabulary = None
Vocabulary._tags_dict = None
Configuration.delete()
try:
payload = {
"name": "hdx_python_api_test_tmp",
"mimeType": "application/vnd.google-apps.folder",
"parents": ["1dvx0H0RG5ZfM9QL148uymWpbuxAqmOzD"],
}
r = gclient.http_client.request(
"post", DRIVE_FILES_API_V3_URL, json=payload, params=params
)
folderid = r.json()["id"]
yield gclient, folderid
finally:
payload = {"trashed": True}
url = f"{DRIVE_FILES_API_V3_URL}/{folderid}"
gclient.http_client.request(
"patch", url, json=payload, params=params
)
Vocabulary._approved_vocabulary = None
Vocabulary._tags_dict = None
Configuration.delete()

def test_create_dataset(
self,
Expand Down
2 changes: 1 addition & 1 deletion tests/hdx/api/test_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_validlocations(self, project_config_yaml):
== "St. Helena"
)
Configuration.setup(MyConfiguration())
Locations.set_validlocations(None)
Locations._validlocations = None
assert Locations.get_HDX_code_from_location("zaf") == "ZAF"
assert Locations.get_HDX_code_from_location_partial("zaf") == (
"ZAF",
Expand Down

0 comments on commit 8d0f5f1

Please sign in to comment.