-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error handling for curie endpoints and add tests for them
- Loading branch information
1 parent
3afc029
commit e13e596
Showing
2 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from prez.app import app | ||
|
||
|
||
@pytest.fixture | ||
def client() -> TestClient: | ||
testclient = TestClient(app) | ||
|
||
# Make a request for the following IRI to ensure | ||
# the curie is available in the 'test_curie' test. | ||
iri = "http://example.com/namespace/test" | ||
response = testclient.get(f"/identifier/curie/{iri}") | ||
assert response.status_code == 200 | ||
assert response.text == "nmspc:test" | ||
|
||
return testclient | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"iri, expected_status_code", | ||
[ | ||
["d", 400], | ||
["http://!", 400], | ||
["http://example.com/namespace", 200], | ||
], | ||
) | ||
def test_iri(iri: str, expected_status_code: int, client: TestClient): | ||
response = client.get(f"/identifier/curie/{iri}") | ||
assert response.status_code == expected_status_code | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"curie, expected_status_code", | ||
[ | ||
["d", 400], | ||
["ns1", 400], | ||
["nmspc:test", 200], | ||
], | ||
) | ||
def test_curie(curie: str, expected_status_code: int, client: TestClient): | ||
response = client.get(f"/identifier/iri/{curie}") | ||
assert response.status_code == expected_status_code |