-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests if connecting for if odk central fails
- Loading branch information
1 parent
05ba6d7
commit cbee779
Showing
1 changed file
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
||
|
||
|
@@ -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 |