-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b11f64
commit 0856bd6
Showing
8 changed files
with
302 additions
and
3 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pytest | ||
|
||
from geoservercloud import GeoServerCloud | ||
|
||
GEOSERVER_URL = "http://localhost:8080/geoserver" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def geoserver(): | ||
geoserver = GeoServerCloud(url=GEOSERVER_URL) | ||
yield geoserver |
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 |
---|---|---|
@@ -0,0 +1,184 @@ | ||
from collections.abc import Generator | ||
from typing import Any | ||
|
||
import pytest | ||
import responses | ||
from responses import matchers | ||
|
||
from geoservercloud.geoservercloud import GeoServerCloud | ||
from tests.conftest import GEOSERVER_URL | ||
|
||
WORKSPACE = "test_workspace" | ||
STORE = "test_store" | ||
HOST = "localhost" | ||
PORT = 5432 | ||
DATABASE = "test_db" | ||
USER = "test_user" | ||
PASSWORD = "test_password" | ||
SCHEMA = "test_schema" | ||
JNDI = "java:comp/env/jdbc/data" | ||
DESCRIPTION = "test description" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def pg_payload() -> Generator[dict[str, dict[str, Any]], Any, None]: | ||
yield { | ||
"dataStore": { | ||
"name": STORE, | ||
"connectionParameters": { | ||
"entry": [ | ||
{"@key": "dbtype", "$": "postgis"}, | ||
{"@key": "host", "$": HOST}, | ||
{"@key": "port", "$": PORT}, | ||
{"@key": "database", "$": DATABASE}, | ||
{"@key": "user", "$": USER}, | ||
{"@key": "passwd", "$": PASSWORD}, | ||
{"@key": "schema", "$": SCHEMA}, | ||
{ | ||
"@key": "namespace", | ||
"$": f"http://{WORKSPACE}", | ||
}, | ||
{"@key": "Expose primary keys", "$": "true"}, | ||
] | ||
}, | ||
} | ||
} | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def jndi_payload() -> Generator[dict[str, dict[str, Any]], Any, None]: | ||
yield { | ||
"dataStore": { | ||
"name": STORE, | ||
"description": DESCRIPTION, | ||
"connectionParameters": { | ||
"entry": [ | ||
{"@key": "dbtype", "$": "postgis"}, | ||
{ | ||
"@key": "jndiReferenceName", | ||
"$": JNDI, | ||
}, | ||
{ | ||
"@key": "schema", | ||
"$": SCHEMA, | ||
}, | ||
{ | ||
"@key": "namespace", | ||
"$": f"http://{WORKSPACE}", | ||
}, | ||
{"@key": "Expose primary keys", "$": "true"}, | ||
] | ||
}, | ||
} | ||
} | ||
|
||
|
||
def test_create_pg_datastore( | ||
geoserver: GeoServerCloud, pg_payload: dict[str, dict[str, Any]] | ||
) -> None: | ||
with responses.RequestsMock() as rsps: | ||
rsps.get( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{WORKSPACE}/datastores/{STORE}.json", | ||
status=404, | ||
) | ||
rsps.post( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{WORKSPACE}/datastores.json", | ||
status=201, | ||
json={"workspace": {"name": WORKSPACE}}, | ||
match=[matchers.json_params_matcher(pg_payload)], | ||
) | ||
|
||
response = geoserver.create_pg_datastore( | ||
workspace=WORKSPACE, | ||
datastore=STORE, | ||
pg_host=HOST, | ||
pg_port=PORT, | ||
pg_db=DATABASE, | ||
pg_user=USER, | ||
pg_password=PASSWORD, | ||
pg_schema=SCHEMA, | ||
) | ||
|
||
assert response | ||
assert response.status_code == 201 | ||
|
||
|
||
def test_update_pg_datastore( | ||
geoserver: GeoServerCloud, pg_payload: dict[str, dict[str, Any]] | ||
) -> None: | ||
with responses.RequestsMock() as rsps: | ||
rsps.get( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{WORKSPACE}/datastores/{STORE}.json", | ||
status=200, | ||
) | ||
rsps.put( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{WORKSPACE}/datastores/{STORE}.json", | ||
status=200, | ||
match=[matchers.json_params_matcher(pg_payload)], | ||
) | ||
|
||
response = geoserver.create_pg_datastore( | ||
workspace=WORKSPACE, | ||
datastore=STORE, | ||
pg_host=HOST, | ||
pg_port=PORT, | ||
pg_db=DATABASE, | ||
pg_user=USER, | ||
pg_password=PASSWORD, | ||
pg_schema=SCHEMA, | ||
) | ||
|
||
assert response | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_create_jndi_datastore( | ||
geoserver: GeoServerCloud, jndi_payload: dict[str, dict[str, Any]] | ||
) -> None: | ||
with responses.RequestsMock() as rsps: | ||
rsps.get( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{WORKSPACE}/datastores/{STORE}.json", | ||
status=404, | ||
) | ||
rsps.post( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{WORKSPACE}/datastores.json", | ||
status=201, | ||
match=[matchers.json_params_matcher(jndi_payload)], | ||
) | ||
|
||
response = geoserver.create_jndi_datastore( | ||
workspace=WORKSPACE, | ||
datastore=STORE, | ||
jndi_reference=JNDI, | ||
pg_schema=SCHEMA, | ||
description=DESCRIPTION, | ||
) | ||
|
||
assert response | ||
assert response.status_code == 201 | ||
|
||
|
||
def test_update_jndi_datastore( | ||
geoserver: GeoServerCloud, jndi_payload: dict[str, dict[str, Any]] | ||
) -> None: | ||
with responses.RequestsMock() as rsps: | ||
rsps.get( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{WORKSPACE}/datastores/{STORE}.json", | ||
status=200, | ||
) | ||
rsps.put( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{WORKSPACE}/datastores/{STORE}.json", | ||
status=200, | ||
match=[matchers.json_params_matcher(jndi_payload)], | ||
) | ||
|
||
response = geoserver.create_jndi_datastore( | ||
workspace=WORKSPACE, | ||
datastore=STORE, | ||
jndi_reference=JNDI, | ||
pg_schema=SCHEMA, | ||
description=DESCRIPTION, | ||
) | ||
|
||
assert response | ||
assert response.status_code == 200 |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import responses | ||
from responses import matchers | ||
|
||
from geoservercloud.geoservercloud import GeoServerCloud | ||
from tests.conftest import GEOSERVER_URL | ||
|
||
|
||
def test_create_workspace(geoserver: GeoServerCloud) -> None: | ||
workspace = "test_workspace" | ||
isolated = True | ||
|
||
with responses.RequestsMock() as rsps: | ||
rsps.post( | ||
url=f"{GEOSERVER_URL}/rest/workspaces.json", | ||
status=201, | ||
match=[ | ||
matchers.json_params_matcher( | ||
{ | ||
"workspace": { | ||
"name": workspace, | ||
"isolated": isolated, | ||
} | ||
} | ||
) | ||
], | ||
) | ||
|
||
response = geoserver.create_workspace(workspace, isolated=isolated) | ||
|
||
assert response.status_code == 201 | ||
|
||
|
||
def test_update_workspace(geoserver: GeoServerCloud) -> None: | ||
workspace = "test_workspace" | ||
|
||
with responses.RequestsMock() as rsps: | ||
rsps.post( | ||
url=f"{GEOSERVER_URL}/rest/workspaces.json", | ||
status=409, | ||
) | ||
rsps.put( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{workspace}.json", | ||
status=200, | ||
) | ||
|
||
response = geoserver.create_workspace(workspace) | ||
|
||
assert response.status_code == 200 | ||
|
||
|
||
def test_delete_workspace(geoserver: GeoServerCloud) -> None: | ||
workspace = "test_workspace" | ||
|
||
with responses.RequestsMock() as rsps: | ||
rsps.delete( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{workspace}.json", | ||
status=200, | ||
) | ||
|
||
response = geoserver.delete_workspace(workspace) | ||
|
||
assert response.status_code == 200 | ||
|
||
|
||
def test_recreate_workspace(geoserver: GeoServerCloud) -> None: | ||
workspace = "test_workspace" | ||
|
||
with responses.RequestsMock() as rsps: | ||
rsps.delete( | ||
url=f"{GEOSERVER_URL}/rest/workspaces/{workspace}.json", | ||
status=200, | ||
) | ||
rsps.post( | ||
url=f"{GEOSERVER_URL}/rest/workspaces.json", | ||
status=201, | ||
) | ||
|
||
response = geoserver.recreate_workspace(workspace) | ||
|
||
assert response.status_code == 201 |