From 9c710ed93de1139426c362f9d438febc7df3e567 Mon Sep 17 00:00:00 2001 From: nazarfil Date: Tue, 24 Dec 2024 08:47:49 +0100 Subject: [PATCH] add test for connection initialisation --- tests/dhis2/test_dhis2.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/dhis2/test_dhis2.py b/tests/dhis2/test_dhis2.py index 165abbb..ef4cee4 100644 --- a/tests/dhis2/test_dhis2.py +++ b/tests/dhis2/test_dhis2.py @@ -17,6 +17,33 @@ def con(): return Connection("http://localhost:8080", "admin", "district") +@responses.activate +@pytest.mark.parametrize("version", VERSIONS) +def test_connection_from_object(version, con): + responses_dir = Path("tests", "dhis2", "responses", version) + responses._add_from_file(Path(responses_dir, "dhis2_init.yaml")) + api = DHIS2(con, cache_dir=None) + assert api is not None + + +@responses.activate +@pytest.mark.parametrize("version", VERSIONS) +def test_connection_from_kwargs(version): + responses_dir = Path("tests", "dhis2", "responses", version) + responses._add_from_file(Path(responses_dir, "dhis2_init.yaml")) + api = DHIS2(url="http://localhost:8080", username="admin", password="district", cache_dir=None) + assert api is not None + + +@responses.activate +@pytest.mark.parametrize("version", VERSIONS) +def test_connection_from_kwargs(version): + responses_dir = Path("tests", "dhis2", "responses", version) + responses._add_from_file(Path(responses_dir, "dhis2_init.yaml")) + with pytest.raises(DHIS2Error): + api = DHIS2(url="http://localhost:8080", cache_dir=None) + + @responses.activate @pytest.mark.parametrize("version", VERSIONS) def test_data_elements(version, con):