Skip to content

Commit

Permalink
Add first test
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarans committed Mar 4, 2025
1 parent 6909f43 commit 3f5b91d
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 8 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/run-python-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ name: Run tests

on:
workflow_dispatch: # add run button in github
# push:
# branches-ignore:
# - gh-pages
# - 'dependabot/**'
# pull_request:
# branches-ignore:
# - gh-pages
push:
branches-ignore:
- gh-pages
- 'dependabot/**'
pull_request:
branches-ignore:
- gh-pages

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt
aiodns==3.2.0
# via aiohttp
aiohappyeyeballs==2.4.6
aiohappyeyeballs==2.4.8
# via aiohttp
aiohttp==3.11.13
# via hdx-resource-changedetection (pyproject.toml)
Expand Down
96 changes: 96 additions & 0 deletions tests/test_headretrieval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""
Unit tests for the retrieval class.
"""

from pytest_check import check

from hdx.resource.changedetection.head_retrieval import HeadRetrieval


class TestHeadRetrieve:
def test_retrieval(self):
url1 = "https://itcorp.com"
url2 = "https://github.com/mcarans/hdx-data-freshness/raw/d1616d76c3b6b8ef5029eb6964b93cde688efd53/tests/fixtures/day0/notfound"
url3 = "file://lala:10"
url4 = "https://ocha-dap.github.io/hdx-data-freshness/tests/fixtures/retrieve/COD_MOZ_Admin0.geojson"
url5 = "https://ocha-dap.github.io/hdx-data-freshness/tests/fixtures/retrieve/hotosm_nic_airports_lines_shp.zip"
url6 = "https://ocha-dap.github.io/hdx-data-freshness/tests/fixtures/retrieve/Dataset.csv"
url7 = "https://ocha-dap.github.io/hdx-data-freshness/tests/fixtures/retrieve/list_one.xls"
url8 = "https://ocha-dap.github.io/hdx-data-freshness/tests/fixtures/retrieve/ACLED-Country-Coverage-and-ISO-Codes_8.2019.xlsx"
url9 = "https://ocha-dap.github.io/hdx-data-freshness/tests/fixtures/retrieve/response.html"
urls = [
(url1, "1", "html"),
(url2, "2", "csv"),
(url3, "3", "csv"),
(url4, "4", "geojson"),
(url5, "5", "shp"),
(url6, "6", "csv"),
(url7, "7", "xls"),
(url8, "8", "xlsx"),
(url9, "9", "html"),
(url9, "10", "csv"),
(url9, "11", "xls"),
]
result = HeadRetrieval(
"test",
{"itcorp.com", "github.com", "ocha-dap.github.io", "lala:10"},
).retrieve(urls)
check.equal(
result["1"],
(
"859",
"Sat, 20 Dec 2014 12:44:12 GMT",
'"35b-50aa52ea9f4dc"',
200,
),
)
check.equal(result["2"], (None, None, None, 404))
check.equal(result["3"], (None, None, None, -100))
check.equal(
result["4"],
(
"176643",
"Tue, 12 Mar 2024 03:15:06 GMT",
'W/"65efc8ba-91a08"',
200,
),
)
check.equal(
result["5"],
("8461", "Tue, 12 Mar 2024 03:15:06 GMT", '"65efc8ba-210d"', 200),
)
check.equal(
result["6"],
(
"11169",
"Tue, 12 Mar 2024 03:15:06 GMT",
'W/"65efc8ba-65e4"',
200,
),
)
check.equal(
result["7"],
(
"81920",
"Tue, 12 Mar 2024 03:15:06 GMT",
'"65efc8ba-14000"',
200,
),
)
check.equal(
result["8"],
("20984", "Tue, 12 Mar 2024 03:15:06 GMT", '"65efc8ba-51f8"', 200),
)
check.equal(
result["9"],
("871", "Tue, 12 Mar 2024 03:15:06 GMT", 'W/"65efc8ba-7e1"', 200),
)
check.equal(
result["10"],
("871", "Tue, 12 Mar 2024 03:15:06 GMT", 'W/"65efc8ba-7e1"', 200),
)
check.equal(
result["11"],
("871", "Tue, 12 Mar 2024 03:15:06 GMT", 'W/"65efc8ba-7e1"', 200),
)

0 comments on commit 3f5b91d

Please sign in to comment.