Skip to content

Commit

Permalink
added tests for ws
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnaglodha committed Nov 5, 2024
1 parent 194e6df commit 040e412
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/_async/test_gsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"

Expand Down Expand Up @@ -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(
Expand Down
30 changes: 30 additions & 0 deletions tests/_sync/test_gsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"

Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"}
Expand Down
12 changes: 12 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)
from geoserverx.models.workspace import (
NewWorkspace,
UpdateWorkspace,
WorkspaceInBulk,
WorkspaceModel,
WorkspacesModel,
Expand Down Expand Up @@ -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)

0 comments on commit 040e412

Please sign in to comment.