diff --git a/tests/_async/test_gsx.py b/tests/_async/test_gsx.py index 1e5fb39..afd8e52 100644 --- a/tests/_async/test_gsx.py +++ b/tests/_async/test_gsx.py @@ -7,6 +7,7 @@ from geoserverx._async.gsx import AsyncGeoServerX, GeoServerXAuth, GeoServerXError from geoserverx.models.geofence import Rule +from geoserverx.models.workspace import UpdateWorkspaceInfo baseUrl = "http://127.0.0.1:8080/geoserver/rest/" @@ -89,6 +90,43 @@ async def test_get_workspace_ConnectError(create_a_client, respx_mock): assert response.response == "Error in connecting to Geoserver" +# Test - update_workspace +@pytest_mark.anyio +async def test_update_workspace_validation( + create_a_client, bad_update_workspace_connection, respx_mock +): + respx_mock.put(f"{baseUrl}workspaces/tiger.json").mock( + return_value=httpx.Response(404, json=bad_update_workspace_connection) + ) + response = await create_a_client.update_workspace( + "tiger", UpdateWorkspaceInfo(isolated=True) + ) + assert response.response == "Result not found" + + +@pytest_mark.anyio +async def test_update_workspace_success( + create_a_client, good_update_workspace_connection, respx_mock +): + respx_mock.put(f"{baseUrl}workspaces/tiger.json").mock( + return_value=httpx.Response(200, json=good_update_workspace_connection) + ) + response = await create_a_client.update_workspace( + "tiger", UpdateWorkspaceInfo(isolated=True) + ) + assert response.code == 200 + + +@pytest_mark.anyio +async def test_update_workspace_ConnectError(create_a_client, respx_mock): + respx.put(f"{baseUrl}workspaces/tiger.json").mock(side_effect=httpx.ConnectError) + with pytest.raises(httpx.ConnectError): + response = await create_a_client.update_workspace( + "tiger", UpdateWorkspaceInfo(isolated=True) + ) + assert response.response == "Error in connecting to Geoserver" + + # Test - get_vector_stores_in_workspaces @pytest_mark.anyio async def test_get_vector_stores_in_workspaces_validation( diff --git a/tests/_sync/test_gsx.py b/tests/_sync/test_gsx.py index 35d2a24..9b0fdbd 100644 --- a/tests/_sync/test_gsx.py +++ b/tests/_sync/test_gsx.py @@ -4,6 +4,7 @@ from geoserverx._sync.gsx import GeoServerXAuth, GeoServerXError, SyncGeoServerX from geoserverx.models.geofence import Rule +from geoserverx.models.workspace import UpdateWorkspaceInfo baseUrl = "http://127.0.0.1:8080/geoserver/rest/" @@ -78,6 +79,35 @@ def test_get_workspace_ConnectError(client: SyncGeoServerX, respx_mock): assert response.response == "Error in connecting to Geoserver" +# Test - update_workspace +def test_update_workspace_validation( + client: SyncGeoServerX, bad_update_workspace_connection, respx_mock +): + respx_mock.put(f"{baseUrl}workspaces/tiger.json").mock( + return_value=httpx.Response(404, json=bad_update_workspace_connection) + ) + response = client.update_workspace("tiger", UpdateWorkspaceInfo(isolated=True)) + assert response.response == "Result not found" + + +def test_update_workspace_success( + client: SyncGeoServerX, good_update_workspace_connection, respx_mock +): + respx_mock.put(f"{baseUrl}workspaces/tiger.json").mock( + return_value=httpx.Response(200, json=good_update_workspace_connection) + ) + response = client.update_workspace("tiger", UpdateWorkspaceInfo(isolated=True)) + assert response.code == 200 + + +def test_update_workspace_ConnectError(client: SyncGeoServerX, respx_mock): + respx_mock.put(f"{baseUrl}workspaces/tiger.json").mock( + side_effect=httpx.ConnectError + ) + response = client.update_workspace("tiger", UpdateWorkspaceInfo(isolated=True)) + assert response.response == "Error in connecting to Geoserver" + + # Test - get_vector_stores_in_workspaces def test_get_vector_stores_in_workspaces_validation( client: SyncGeoServerX, invalid_datastores_model_connection, respx_mock diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index 1e22a09..faeed68 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -54,6 +54,37 @@ def test_get_workspace_ConnectError(respx_mock): assert "Error in connecting to Geoserver" in result.stdout +# Test - update_workspace +def test_update_workspace_validation(bad_update_workspace_connection, respx_mock): + respx_mock.put(f"{baseUrl}workspaces/tiger.json").mock( + return_value=httpx.Response(404, json=bad_update_workspace_connection) + ) + result = runner.invoke( + app, ["update-workspace", "--current-name", "tiger", "--isolated"] + ) + assert "Result not found" in result.stdout + + +def test_update_workspace_success(good_update_workspace_connection, respx_mock): + respx_mock.put(f"{baseUrl}workspaces/tiger.json").mock( + return_value=httpx.Response(200, json=good_update_workspace_connection) + ) + result = runner.invoke( + app, ["update-workspace", "--current-name", "tiger", "--isolated"] + ) + assert "200" in result.stdout + + +def test_update_workspace_ConnectError(respx_mock): + respx_mock.put(f"{baseUrl}workspaces/tiger.json").mock( + side_effect=httpx.ConnectError + ) + result = runner.invoke( + app, ["update-workspace", "--current-name", "tiger", "--isolated"] + ) + assert "Error in connecting to Geoserver" in result.stdout + + # Test - get_vector_stores_in_workspaces def test_get_vector_stores_in_workspaces_validation( invalid_datastores_model_connection, respx_mock diff --git a/tests/conftest.py b/tests/conftest.py index f5a976b..46124c6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -58,6 +58,24 @@ def networkbad_workspace_connection() -> dict: return item +@pytest.fixture +def good_update_workspace_connection() -> dict: + item = {"workspace": {"isolated": True}} + return item + + +@pytest.fixture +def bad_update_workspace_connection() -> dict: + item = {"workspace": ""} + return item + + +@pytest.fixture +def invalid_update_workspace_connection() -> dict: + item = {"code": 404, "response": "Result not found"} + return item + + @pytest.fixture def good_datastore_in_bulk_connection() -> dict: item = {"name": "just", "href": "https://www.linkedin.com/notifications/"} diff --git a/tests/test_models.py b/tests/test_models.py index 1fe098c..145e491 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -27,6 +27,7 @@ ) from geoserverx.models.workspace import ( NewWorkspace, + UpdateWorkspace, WorkspaceInBulk, WorkspaceModel, WorkspacesModel, @@ -287,3 +288,14 @@ def test_RulesResponse_connection(good_all_geofence_rules_connection): def test_RulesResponse_failure(bad_all_geofence_rules_connection): with pytest.raises(ValidationError): RulesResponse(**bad_all_geofence_rules_connection) + + +# Testing UpdateWorkspace +def test_UpdateWorkspace_connection(good_update_workspace_connection): + ds_connection = UpdateWorkspace(**good_update_workspace_connection) + assert ds_connection.workspace.isolated is True + + +def test_UpdateWorkspace_failure(bad_update_workspace_connection): + with pytest.raises(ValidationError): + UpdateWorkspace(**bad_update_workspace_connection)