Skip to content

Commit

Permalink
Fix hydroshare tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed Dec 17, 2024
1 parent d71efb8 commit f7dfff1
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions tests/unit/contentproviders/test_hydroshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,14 @@ def doi_resolver(req, context):
}


def test_content_id(requests_mock):
requests_mock.get(re.compile("https://"), json=hydroshare_data)
requests_mock.get(re.compile("https://doi.org"), json=doi_resolver)

def test_content_id():
hydro = Hydroshare()

hydro.detect("10.4211/hs.b8f6eae9d89241cf8b5904033460af61")
assert hydro.content_id == "b8f6eae9d89241cf8b5904033460af61.v1569427757"

assert hydro.content_id == "b8f6eae9d89241cf8b5904033460af61.v1585005408"

def test_detect_hydroshare(requests_mock):
requests_mock.get(re.compile("https://"), json=hydroshare_data)
requests_mock.get(re.compile("https://doi.org"), json=doi_resolver)

def test_detect_hydroshare():
# valid Hydroshare DOIs trigger this content provider
expected = {
"host": {
Expand All @@ -59,7 +53,7 @@ def test_detect_hydroshare(requests_mock):
"version": "https://www.hydroshare.org/hsapi/resource/{}/scimeta/elements",
},
"resource": "b8f6eae9d89241cf8b5904033460af61",
"version": "1569427757",
"version": "1585005408",
}

assert (
Expand All @@ -68,26 +62,17 @@ def test_detect_hydroshare(requests_mock):
)
== expected
)
# assert a call to urlopen was called to fetch version
assert requests_mock.call_count == 1
requests_mock.reset_mock()

assert (
Hydroshare().detect("10.4211/hs.b8f6eae9d89241cf8b5904033460af61") == expected
)
# assert 3 calls were made, 2 to resolve the DOI (302 + 200) and another to fetch the version
assert requests_mock.call_count == 3
requests_mock.reset_mock()

assert (
Hydroshare().detect(
"https://doi.org/10.4211/hs.b8f6eae9d89241cf8b5904033460af61"
)
== expected
)
# assert 3 more calls were made, 2 to resolve the DOI and another to fetch the version
assert requests_mock.call_count == 3
requests_mock.reset_mock()

# Don't trigger the Hydroshare content provider
assert Hydroshare().detect("/some/path/here") is None
Expand Down

0 comments on commit f7dfff1

Please sign in to comment.