Skip to content

Commit

Permalink
test: add tests if connecting for if odk central fails
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Apr 19, 2024
1 parent 05ba6d7 commit cbee779
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import requests
import segno

from osm_fieldwork.OdkCentral import OdkCentral
from osm_fieldwork.OdkCentralAsync import OdkCentral as OdkCentralAsync

testdata_dir = Path(__file__).parent / "testdata"


Expand Down Expand Up @@ -224,3 +227,26 @@ def test_form_fields(odk_form_cleanup):
"binary": None,
"selectMultiple": None,
}


def test_invalid_connection_sync():
"""Test case when connection to Central fails, sync code."""
central = OdkCentral("https://proxy", "[email protected]", "Password1234")
assert central.listProjects() == []

with pytest.raises(ConnectionError, match="Failed to connect to Central. Is the URL valid?"):
OdkCentral("https://somerandominvalidurl546456546.xyz", "[email protected]", "Password1234")

with pytest.raises(ConnectionError, match="ODK credentials are invalid, or may have changed. Please update them."):
OdkCentral("https://proxy", "[email protected]", "Password1234")


async def test_invalid_connection_async():
"""Test case when connection to Central fails, async code."""
with pytest.raises(ConnectionError, match="Failed to connect to Central. Is the URL valid?"):
async with OdkCentralAsync("https://somerandominvalidurl546456546.xyz", "[email protected]", "Password1234"):
pass

with pytest.raises(ConnectionError, match="ODK credentials are invalid, or may have changed. Please update them."):
async with OdkCentralAsync("https://proxy", "[email protected]", "Password1234"):
pass

0 comments on commit cbee779

Please sign in to comment.