From 8f0cb92b557334fc3bd0da21b04ea27438a892bc Mon Sep 17 00:00:00 2001 From: Andrea Borghi Date: Mon, 14 Oct 2024 21:00:08 +0200 Subject: [PATCH] Implement review comments --- geoservercloud/geoservercloud.py | 5 +- geoservercloud/models/common.py | 37 ++++++-- geoservercloud/models/featuretype.py | 4 +- geoservercloud/models/workspaces.py | 1 - geoservercloud/templates.py | 131 ++++++++++++++------------- tests/models/test_common.py | 66 +------------- tests/models/test_datastore.py | 8 +- tests/models/test_datastores.py | 6 +- tests/models/test_featuretype.py | 13 +-- tests/models/test_featuretypes.py | 3 - tests/models/test_style.py | 41 ++------- tests/models/test_styles.py | 7 +- tests/models/test_workspace.py | 25 ----- tests/models/test_workspaces.py | 9 +- tests/resources/test_resource.py | 2 +- tests/test_acl.py | 2 +- tests/test_cascaded_wmts.py | 2 +- tests/test_datastore.py | 8 +- tests/test_feature_type.py | 2 +- tests/test_gwc.py | 2 +- tests/test_layer_group.py | 2 +- tests/test_role.py | 2 +- tests/test_style.py | 3 +- tests/test_user.py | 2 +- tests/test_wfs.py | 2 +- tests/test_wms.py | 2 +- tests/test_workspace.py | 2 +- 27 files changed, 134 insertions(+), 255 deletions(-) diff --git a/geoservercloud/geoservercloud.py b/geoservercloud/geoservercloud.py index fe3bf11..8f25b88 100644 --- a/geoservercloud/geoservercloud.py +++ b/geoservercloud/geoservercloud.py @@ -306,6 +306,7 @@ def create_wmts_store( self.rest_endpoints.wmtsstore(workspace_name, name), json=payload ) + # TODO: add a test for this method def get_feature_types( self, workspace_name: str, datastore_name: str ) -> dict[str, Any]: @@ -319,6 +320,7 @@ def get_feature_types( ) return featuretypes + # TODO: add a test for this method def get_feature_type( self, workspace_name: str, datastore_name: str, feature_type_name: str ) -> dict[str, Any]: @@ -337,7 +339,7 @@ def create_feature_type( datastore: str | None = None, title: str | dict = "Default title", abstract: str | dict = "Default abstract", - attributes: dict = Templates.geom_point_attribute(), + attributes: dict = Templates.geom_point_attribute(), # TODO: remove default value, because if should be None epsg: int = 4326, ) -> Response: """ @@ -349,6 +351,7 @@ def create_feature_type( datastore = datastore or self.default_datastore if not datastore: raise ValueError("Datastore not provided") + # TODO: use FeatureType.post_payload() payload: dict[str, dict[str, Any]] = Templates.feature_type( layer=layer, workspace=workspace_name, diff --git a/geoservercloud/models/common.py b/geoservercloud/models/common.py index f86f8bf..3028ed7 100644 --- a/geoservercloud/models/common.py +++ b/geoservercloud/models/common.py @@ -50,10 +50,28 @@ def update(self, other: dict): # type: ignore class I18N: """ - Class to handle internationalization of strings - items like title, abstract, etc. that can be internationalized - become a dictionary with the key being the language code - and their key in the payload changes to internationalizedTitle, internationalizedAbstract, etc. + Geoserver handles internationalization with 2 possible (mutually exclusive) keys in the rest payload: + either: + - [key: string] + or + - [internationalKey: dictionary] + + example: + a) as key: string we get {"title": "Test Title"} + b) as key: dict we get {"internationalTitle": {"en": "Test Title", "es": "Título de Prueba"}} + + This class gives a layer of abstraction to handle both cases. + + Usage: + Call the class by adding both possible keys in a tuple and the value. + + Parameters: + keys: tuple[str, str] example : ("title", "internationalTitle") + value: str | dict example: "Test Title" | {"en": "Test Title", "es": "Título de Prueba"} + + Example: + + my_i18n = I18N(("title", "internationalTitle"), "Test Title") """ def __init__(self, keys: tuple[str, Any], value: str | dict) -> None: @@ -61,9 +79,9 @@ def __init__(self, keys: tuple[str, Any], value: str | dict) -> None: self._i18n_key = keys[1] self._value = value if isinstance(value, str): - self._payload = (self.str_key, self._value) + self._content = {self.str_key: self._value} elif isinstance(value, dict): - self._payload = (self._i18n_key, self._value) # type: ignore + self._content = {self._i18n_key: self._value} else: raise ValueError("Invalid value type") @@ -79,9 +97,8 @@ def i18n_key(self): def value(self): return self._value - @property - def payload_tuple(self): - return self._payload + def asdict(self): + return self._content def __repr__(self): - return json.dumps({self._payload[0]: self._payload[1]}, indent=4) + return json.dumps(self._content, indent=4) diff --git a/geoservercloud/models/featuretype.py b/geoservercloud/models/featuretype.py index 3ca163a..dc9a324 100644 --- a/geoservercloud/models/featuretype.py +++ b/geoservercloud/models/featuretype.py @@ -72,12 +72,12 @@ def post_payload(self): "featureType": { "name": self.name, "nativeName": self.native_name, - self._title.payload_tuple[0]: self._title.payload_tuple[1], - self._abstract.payload_tuple[0]: self._abstract.payload_tuple[1], "srs": self.srs, "keywords": self.keywords, } } + payload["featureType"].update(self.title.asdict()) + payload["featureType"].update(self.abstract.asdict()) if self.metadataLink != {}: payload["featureType"]["metadataLinks"] = self.metadataLink if self.attributes: diff --git a/geoservercloud/models/workspaces.py b/geoservercloud/models/workspaces.py index b27dc3e..90a72f0 100644 --- a/geoservercloud/models/workspaces.py +++ b/geoservercloud/models/workspaces.py @@ -19,7 +19,6 @@ def workspaces(self): @classmethod def from_response(cls, response: Response): - # Parse the JSON response json_data = response.json() workspaces = [] diff --git a/geoservercloud/templates.py b/geoservercloud/templates.py index addea36..992c161 100644 --- a/geoservercloud/templates.py +++ b/geoservercloud/templates.py @@ -83,71 +83,72 @@ def workspace_wms(workspace: str) -> dict[str, dict[str, Any]]: } } - @staticmethod - def postgis_data_store( - datastore: str, - pg_host: str, - pg_port: int, - pg_db: str, - pg_user: str, - pg_password: str, - namespace: str, - pg_schema: str = "public", - ) -> dict[str, dict[str, Any]]: - return { - "dataStore": { - "name": datastore, - "connectionParameters": { - "entry": [ - {"@key": "dbtype", "$": "postgis"}, - {"@key": "host", "$": pg_host}, - {"@key": "port", "$": pg_port}, - {"@key": "database", "$": pg_db}, - {"@key": "user", "$": pg_user}, - {"@key": "passwd", "$": pg_password}, - {"@key": "schema", "$": pg_schema}, - { - "@key": "namespace", - "$": namespace, - }, - {"@key": "Expose primary keys", "$": "true"}, - ] - }, - } - } + # TODO: verify that we don't need these 2 templates anymore + # @staticmethod + # def postgis_data_store( + # datastore: str, + # pg_host: str, + # pg_port: int, + # pg_db: str, + # pg_user: str, + # pg_password: str, + # namespace: str, + # pg_schema: str = "public", + # ) -> dict[str, dict[str, Any]]: + # return { + # "dataStore": { + # "name": datastore, + # "connectionParameters": { + # "entry": [ + # {"@key": "dbtype", "$": "postgis"}, + # {"@key": "host", "$": pg_host}, + # {"@key": "port", "$": pg_port}, + # {"@key": "database", "$": pg_db}, + # {"@key": "user", "$": pg_user}, + # {"@key": "passwd", "$": pg_password}, + # {"@key": "schema", "$": pg_schema}, + # { + # "@key": "namespace", + # "$": namespace, + # }, + # {"@key": "Expose primary keys", "$": "true"}, + # ] + # }, + # } + # } - @staticmethod - def postgis_jndi_data_store( - datastore: str, - jndi_reference: str, - namespace: str, - pg_schema: str = "public", - description: str | None = None, - ) -> dict[str, dict[str, Any]]: - return { - "dataStore": { - "name": datastore, - "description": description, - "connectionParameters": { - "entry": [ - {"@key": "dbtype", "$": "postgis"}, - { - "@key": "jndiReferenceName", - "$": jndi_reference, - }, - { - "@key": "schema", - "$": pg_schema, - }, - { - "@key": "namespace", - "$": namespace, - }, - {"@key": "Expose primary keys", "$": "true"}, - ] - }, - } - } + # @staticmethod + # def postgis_jndi_data_store( + # datastore: str, + # jndi_reference: str, + # namespace: str, + # pg_schema: str = "public", + # description: str | None = None, + # ) -> dict[str, dict[str, Any]]: + # return { + # "dataStore": { + # "name": datastore, + # "description": description, + # "connectionParameters": { + # "entry": [ + # {"@key": "dbtype", "$": "postgis"}, + # { + # "@key": "jndiReferenceName", + # "$": jndi_reference, + # }, + # { + # "@key": "schema", + # "$": pg_schema, + # }, + # { + # "@key": "namespace", + # "$": namespace, + # }, + # {"@key": "Expose primary keys", "$": "true"}, + # ] + # }, + # } + # } @staticmethod def wmts_store( @@ -173,6 +174,8 @@ def geom_point_attribute() -> dict[str, Any]: } } + # TODO: remove this template after finishing to merge + # BBOX stuff in the FeatureType class @staticmethod def feature_type( layer: str, diff --git a/tests/models/test_common.py b/tests/models/test_common.py index 73f3bde..4d63de6 100644 --- a/tests/models/test_common.py +++ b/tests/models/test_common.py @@ -2,13 +2,12 @@ import pytest -from geoservercloud.models import ( # Adjust import based on your module location +from geoservercloud.models import ( I18N, KeyDollarListDict, ) -# Test initialization with input_list (deserialization) def test_keydollarlistdict_initialization_with_input_list(): input_list = [{"@key": "host", "$": "localhost"}, {"@key": "port", "$": "5432"}] @@ -18,27 +17,12 @@ def test_keydollarlistdict_initialization_with_input_list(): assert kdl_dict["port"] == "5432" -# Test initialization without input_list def test_keydollarlistdict_initialization_without_input_list(): kdl_dict = KeyDollarListDict() - assert len(kdl_dict) == 0 # Should be an empty dictionary + assert kdl_dict == {} -# Test deserialization of input_list -def test_keydollarlistdict_deserialization(): - input_list = [ - {"@key": "username", "$": "admin"}, - {"@key": "password", "$": "secret"}, - ] - - kdl_dict = KeyDollarListDict(input_list) - - assert kdl_dict["username"] == "admin" - assert kdl_dict["password"] == "secret" - - -# Test serialization method def test_keydollarlistdict_serialization(): kdl_dict = KeyDollarListDict() kdl_dict["host"] = "localhost" @@ -52,7 +36,6 @@ def test_keydollarlistdict_serialization(): assert kdl_dict.serialize() == expected_output -# Test __repr__ method def test_keydollarlistdict_repr(): kdl_dict = KeyDollarListDict([{"@key": "db", "$": "postgres"}]) @@ -61,7 +44,6 @@ def test_keydollarlistdict_repr(): assert repr(kdl_dict) == expected_repr -# Test __str__ method def test_keydollarlistdict_str(): kdl_dict = KeyDollarListDict([{"@key": "db", "$": "postgres"}]) @@ -70,7 +52,6 @@ def test_keydollarlistdict_str(): assert str(kdl_dict) == expected_str -# Test initialization with a string value def test_i18n_initialization_string(): keys = ("title", "internationalizedTitle") value = "Test Title" @@ -80,10 +61,9 @@ def test_i18n_initialization_string(): assert i18n_instance.str_key == "title" assert i18n_instance.i18n_key == "internationalizedTitle" assert i18n_instance.value == value - assert i18n_instance._payload == ("title", value) + assert i18n_instance.asdict() == {"title": value} -# Test initialization with a dictionary value (internationalized) def test_i18n_initialization_dict(): keys = ("abstract", "internationalizedAbstract") value = {"en": "Test Abstract", "fr": "Résumé Test"} @@ -93,53 +73,17 @@ def test_i18n_initialization_dict(): assert i18n_instance.str_key == "abstract" assert i18n_instance.i18n_key == "internationalizedAbstract" assert i18n_instance.value == value - assert i18n_instance._payload == ("internationalizedAbstract", value) + assert i18n_instance.asdict() == {"internationalizedAbstract": value} -# Test invalid value type (neither string nor dictionary) def test_i18n_invalid_value_type(): keys = ("title", "internationalizedTitle") - value = 123 # Invalid value type + value = 123 with pytest.raises(ValueError, match="Invalid value type"): I18N(keys, value) -# Test str_key property -def test_i18n_str_key_property(): - keys = ("title", "internationalizedTitle") - value = "Test Title" - i18n_instance = I18N(keys, value) - - assert i18n_instance.str_key == "title" - - -# Test i18n_key property -def test_i18n_i18n_key_property(): - keys = ("abstract", "internationalizedAbstract") - value = {"en": "Test Abstract", "fr": "Résumé Test"} - i18n_instance = I18N(keys, value) - - assert i18n_instance.i18n_key == "internationalizedAbstract" - - -# Test value property -def test_i18n_value_property(): - keys = ("title", "internationalizedTitle") - value = "Test Title" - i18n_instance = I18N(keys, value) - - assert i18n_instance.value == "Test Title" - - -def test_i18n_payload_tuple_property(): - keys = ("title", "internationalizedTitle") - value = "Test Title" - i18n_instance = I18N(keys, value) - - assert i18n_instance.payload_tuple == ("title", "Test Title") - - def test_i18n_repr(): keys = ("title", "internationalizedTitle") value = "Test Title" diff --git a/tests/models/test_datastore.py b/tests/models/test_datastore.py index b03b101..f9c75c6 100644 --- a/tests/models/test_datastore.py +++ b/tests/models/test_datastore.py @@ -2,13 +2,12 @@ import pytest -from geoservercloud.models import ( # Adjust based on your actual module name +from geoservercloud.models import ( KeyDollarListDict, PostGisDataStore, ) -# Test initialization of the PostGisDataStore class def test_postgisdatastore_initialization(): connection_parameters = KeyDollarListDict( [{"@key": "host", "$": "localhost"}, {"@key": "port", "$": "5432"}] @@ -24,7 +23,6 @@ def test_postgisdatastore_initialization(): assert datastore.data_store_type == "PostGIS" -# Test put_payload method def test_postgisdatastore_put_payload(): connection_parameters = KeyDollarListDict( [{"@key": "host", "$": "localhost"}, {"@key": "port", "$": "5432"}] @@ -51,7 +49,6 @@ def test_postgisdatastore_put_payload(): assert datastore.put_payload() == expected_payload -# Test post_payload method (should return the same as put_payload) def test_postgisdatastore_post_payload(): connection_parameters = KeyDollarListDict( [{"@key": "host", "$": "localhost"}, {"@key": "port", "$": "5432"}] @@ -64,7 +61,6 @@ def test_postgisdatastore_post_payload(): assert datastore.post_payload() == datastore.put_payload() -# Test from_response class method def test_postgisdatastore_from_response(mocker): mock_response = Mock() mock_response.json.return_value = { @@ -85,12 +81,10 @@ def test_postgisdatastore_from_response(mocker): assert datastore.data_store_name == "test_datastore" assert datastore.data_store_type == "PostGIS" - # Check that connection parameters were correctly parsed into a KeyDollarListDict assert datastore.connection_parameters["host"] == "localhost" assert datastore.connection_parameters["port"] == "5432" -# Test parse_connection_parameters method def test_postgisdatastore_parse_connection_parameters(): json_data = { "dataStore": { diff --git a/tests/models/test_datastores.py b/tests/models/test_datastores.py index b8f061d..b91b12d 100644 --- a/tests/models/test_datastores.py +++ b/tests/models/test_datastores.py @@ -2,10 +2,9 @@ import pytest -from geoservercloud.models import DataStores # Replace with the actual module name +from geoservercloud.models import DataStores -# Test initialization of DataStores class def test_datastores_initialization(): workspace_name = "test_workspace" datastores = ["store1", "store2"] @@ -16,7 +15,6 @@ def test_datastores_initialization(): assert ds.datastores == datastores -# Test the from_response class method with a valid response def test_datastores_from_response(mocker): mock_response = Mock() mock_response.json.return_value = { @@ -32,7 +30,6 @@ def test_datastores_from_response(mocker): assert ds.datastores == ["store1", "store2"] -# Test from_response with an empty response def test_datastores_from_response_empty(): mock_response = Mock() mock_response.json.return_value = { @@ -45,7 +42,6 @@ def test_datastores_from_response_empty(): assert ds.datastores == [] -# Test the __repr__ method def test_datastores_repr(): ds = DataStores("test_workspace", ["store1", "store2"]) diff --git a/tests/models/test_featuretype.py b/tests/models/test_featuretype.py index fa0fab3..0aa2847 100644 --- a/tests/models/test_featuretype.py +++ b/tests/models/test_featuretype.py @@ -4,7 +4,6 @@ from geoservercloud.models import I18N, FeatureType -# Test initialization of FeatureType class def test_featuretype_initialization(): feature_type = FeatureType( namespace_name="test_namespace", @@ -21,13 +20,12 @@ def test_featuretype_initialization(): assert feature_type.name == "test_name" assert feature_type.native_name == "test_native_name" assert feature_type.srs == "EPSG:4326" - assert feature_type.title.payload_tuple[1] == "Test Title" - assert feature_type.abstract.payload_tuple[1] == "Test Abstract" + assert feature_type.title.asdict()["title"] == "Test Title" + assert feature_type.abstract.asdict()["abstract"] == "Test Abstract" assert feature_type.keywords == {"keyword1": "test_keyword"} assert feature_type.attributes == {"attribute1": "value1"} -# Test post_payload method def test_featuretype_post_payload(): feature_type = FeatureType( namespace_name="test_namespace", @@ -55,7 +53,6 @@ def test_featuretype_post_payload(): assert feature_type.post_payload() == expected_payload -# Test create_metadata_link method def test_featuretype_create_metadata_link(): feature_type = FeatureType( namespace_name="test_namespace", @@ -77,7 +74,6 @@ def test_featuretype_create_metadata_link(): assert feature_type.metadataLink == expected_metadata_link -# Test from_response method def test_featuretype_from_response(): mock_response = Mock() mock_response.json.return_value = { @@ -106,8 +102,8 @@ def test_featuretype_from_response(): assert feature_type.name == "test_name" assert feature_type.native_name == "test_native_name" assert feature_type.srs == "EPSG:4326" - assert feature_type.title.payload_tuple[1] == "Test Title" - assert feature_type.abstract.payload_tuple[1] == "Test Abstract" + assert feature_type.title.asdict()["title"] == "Test Title" + assert feature_type.abstract.asdict()["abstract"] == "Test Abstract" assert feature_type.keywords == {"keyword1": "test_keyword"} assert feature_type.attributes == {"attribute1": "value1"} assert feature_type.metadataLink == { @@ -119,7 +115,6 @@ def test_featuretype_from_response(): } -# Test __repr__ method def test_featuretype_repr(): feature_type = FeatureType( namespace_name="test_namespace", diff --git a/tests/models/test_featuretypes.py b/tests/models/test_featuretypes.py index 4a623ff..3be58b5 100644 --- a/tests/models/test_featuretypes.py +++ b/tests/models/test_featuretypes.py @@ -6,7 +6,6 @@ from geoservercloud.models import FeatureTypes # Replace with the correct module path -# Test initialization of FeatureTypes class def test_featuretypes_initialization(): featuretypes = ["feature1", "feature2"] feature_types_instance = FeatureTypes(featuretypes) @@ -14,7 +13,6 @@ def test_featuretypes_initialization(): assert feature_types_instance.featuretypes == featuretypes -# Test from_response method with a valid response def test_featuretypes_from_response_valid(): mock_response = Mock() mock_response.status_code = 200 @@ -27,7 +25,6 @@ def test_featuretypes_from_response_valid(): assert feature_types_instance.featuretypes == ["feature1", "feature2"] -# Test __repr__ method def test_featuretypes_repr(): featuretypes = ["feature1", "feature2"] feature_types_instance = FeatureTypes(featuretypes) diff --git a/tests/models/test_style.py b/tests/models/test_style.py index e3ec48a..3374c8e 100644 --- a/tests/models/test_style.py +++ b/tests/models/test_style.py @@ -2,10 +2,9 @@ import pytest -from geoservercloud.models import Style # Adjust based on the actual import path +from geoservercloud.models import Style -# Test initialization of Style class def test_style_initialization(): style = Style( name="test_style", @@ -17,8 +16,8 @@ def test_style_initialization(): date_modified="2023-10-02", legend_url="http://example.com/legend.png", legend_format="image/png", - legend_width="100", - legend_height="100", + legend_width=100, + legend_height=100, ) assert style.name == "test_style" @@ -31,12 +30,11 @@ def test_style_initialization(): assert style.legend == { "onlineResource": "http://example.com/legend.png", "format": "image/png", - "width": "100", - "height": "100", + "width": 100, + "height": 100, } -# Test initialization without a legend def test_style_initialization_without_legend(): style = Style( name="test_style", @@ -49,26 +47,6 @@ def test_style_initialization_without_legend(): assert style.legend is None -# Test create_legend method -def test_style_create_legend(): - style = Style( - name="test_style", - workspace="test_workspace", - legend_url="http://example.com/legend.png", - legend_format="image/png", - legend_width="100", - legend_height="100", - ) - - assert style.legend == { - "onlineResource": "http://example.com/legend.png", - "format": "image/png", - "width": "100", - "height": "100", - } - - -# Test put_payload method with legend def test_style_put_payload_with_legend(mocker): style = Style( name="test_style", @@ -94,11 +72,9 @@ def test_style_put_payload_with_legend(mocker): } } - payload = style.put_payload() - assert payload == expected_payload + assert style.put_payload() == expected_payload -# Test put_payload method without legend def test_style_put_payload_without_legend(mocker): style = Style( name="test_style", @@ -114,11 +90,9 @@ def test_style_put_payload_without_legend(mocker): } } - payload = style.put_payload() - assert payload == expected_payload + assert style.put_payload() == expected_payload -# Test post_payload method def test_style_post_payload(mocker): style = Style( name="test_style", @@ -135,7 +109,6 @@ def test_style_post_payload(mocker): mock_put_payload.assert_called_once() -# Test from_response method def test_style_from_response(): mock_response = Mock() mock_response.json.return_value = { diff --git a/tests/models/test_styles.py b/tests/models/test_styles.py index 9a8eb4a..3775f00 100644 --- a/tests/models/test_styles.py +++ b/tests/models/test_styles.py @@ -2,10 +2,9 @@ import pytest -from geoservercloud.models import Styles # Replace with the correct import path +from geoservercloud.models import Styles -# Test initialization of Styles class def test_styles_initialization(): workspace = "test_workspace" styles = ["style1", "style2"] @@ -16,7 +15,6 @@ def test_styles_initialization(): assert styles_instance.styles == styles -# Test the from_response method with a valid response def test_styles_from_response_valid(): mock_response = Mock() mock_response.json.return_value = { @@ -32,7 +30,6 @@ def test_styles_from_response_valid(): assert styles_instance.styles == ["style1", "style2"] -# Test the from_response method when no workspace is provided def test_styles_from_response_no_workspace(): mock_response = Mock() mock_response.json.return_value = { @@ -45,7 +42,6 @@ def test_styles_from_response_no_workspace(): assert styles_instance.styles == ["style1", "style2"] -# Test the from_response method with empty styles list def test_styles_from_response_empty_styles(): mock_response = Mock() mock_response.json.return_value = { @@ -58,7 +54,6 @@ def test_styles_from_response_empty_styles(): assert styles_instance.styles == [] -# Test the from_response method with no styles section def test_styles_from_response_no_styles_section(): mock_response = Mock() mock_response.json.return_value = {} diff --git a/tests/models/test_workspace.py b/tests/models/test_workspace.py index 39df4e2..5d93ef7 100644 --- a/tests/models/test_workspace.py +++ b/tests/models/test_workspace.py @@ -5,7 +5,6 @@ from geoservercloud.models import Workspace -# Test normal initialization of the Workspace class def test_workspace_initialization(): workspace = Workspace("test_workspace", isolated=True) @@ -13,7 +12,6 @@ def test_workspace_initialization(): assert workspace.isolated is True -# Test the put_payload method with isolated=True def test_workspace_put_payload_isolated(): workspace = Workspace("test_workspace", isolated=True) @@ -22,16 +20,6 @@ def test_workspace_put_payload_isolated(): assert workspace.put_payload() == expected_payload -# Test the put_payload method with isolated=False -def test_workspace_put_payload_not_isolated(): - workspace = Workspace("test_workspace", isolated=False) - - expected_payload = {"workspace": {"name": "test_workspace"}} - - assert workspace.put_payload() == expected_payload - - -# Test the post_payload method (should be the same as put_payload) def test_workspace_post_payload(): workspace = Workspace("test_workspace", isolated=True) @@ -40,7 +28,6 @@ def test_workspace_post_payload(): assert workspace.post_payload() == expected_payload -# Test the from_response class method with isolated=True in response def test_workspace_from_response_isolated(): mock_response = Mock() mock_response.json.return_value = { @@ -53,7 +40,6 @@ def test_workspace_from_response_isolated(): assert workspace.isolated is True -# Test the from_response class method with isolated=False (not present) in response def test_workspace_from_response_not_isolated(): mock_response = Mock() mock_response.json.return_value = {"workspace": {"name": "test_workspace"}} @@ -62,14 +48,3 @@ def test_workspace_from_response_not_isolated(): assert workspace.name == "test_workspace" assert workspace.isolated is False - - -# Test the from_response class method with missing workspace name -def test_workspace_from_response_missing_name(): - mock_response = Mock() - mock_response.json.return_value = {"workspace": {}} - - workspace = Workspace.from_response(mock_response) - - assert workspace.name is None - assert workspace.isolated is False diff --git a/tests/models/test_workspaces.py b/tests/models/test_workspaces.py index a461377..7a6a518 100644 --- a/tests/models/test_workspaces.py +++ b/tests/models/test_workspaces.py @@ -1,12 +1,8 @@ from unittest.mock import Mock -import jsonschema -import pytest - from geoservercloud.models import Workspaces -# Test initialization of the Workspaces class def test_workspaces_initialization(): initial_workspaces = {"Workspace1": "http://example.com/ws1"} workspaces = Workspaces(initial_workspaces) @@ -14,7 +10,6 @@ def test_workspaces_initialization(): assert workspaces.workspaces == initial_workspaces -# Test the find method to ensure it finds existing workspaces def test_workspaces_find_existing(): initial_workspaces = {"Workspace1": "http://example.com/ws1"} workspaces = Workspaces(initial_workspaces) @@ -22,18 +17,16 @@ def test_workspaces_find_existing(): assert workspaces.find("Workspace1") == "http://example.com/ws1" -# Test the find method to ensure it returns None for non-existing workspaces def test_workspaces_find_non_existing(): workspaces = Workspaces({"Workspace1": "http://example.com/ws1"}) assert workspaces.find("NonExistingWorkspace") is None -# Test the from_response method with an empty response def test_workspaces_from_response_empty(): mock_response = Mock() mock_response.json.return_value = {"workspaces": {}} workspaces = Workspaces.from_response(mock_response) - assert len(workspaces.workspaces) == 0 + assert workspaces.workspaces == [] diff --git a/tests/resources/test_resource.py b/tests/resources/test_resource.py index 8bfeea6..029a215 100644 --- a/tests/resources/test_resource.py +++ b/tests/resources/test_resource.py @@ -1,6 +1,6 @@ import responses -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud def test_create_resource(geoserver: GeoServerCloud) -> None: diff --git a/tests/test_acl.py b/tests/test_acl.py index 63d309f..72f70d2 100644 --- a/tests/test_acl.py +++ b/tests/test_acl.py @@ -1,7 +1,7 @@ import responses import responses.matchers -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud def test_create_acl_admin_rule(geoserver: GeoServerCloud) -> None: diff --git a/tests/test_cascaded_wmts.py b/tests/test_cascaded_wmts.py index a5d1a04..1bf8615 100644 --- a/tests/test_cascaded_wmts.py +++ b/tests/test_cascaded_wmts.py @@ -3,7 +3,7 @@ import pytest import responses -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud WORKSPACE = "test_workspace" STORE = "test_wmtsstore" diff --git a/tests/test_datastore.py b/tests/test_datastore.py index e622e4e..999130d 100644 --- a/tests/test_datastore.py +++ b/tests/test_datastore.py @@ -6,8 +6,8 @@ import responses from responses import matchers -from geoservercloud.geoservercloud import GeoServerCloud -from geoservercloud.models import PostGisDataStore # Ensure this import is correct +from geoservercloud import GeoServerCloud +from geoservercloud.models import PostGisDataStore from tests.conftest import GEOSERVER_URL WORKSPACE = "test_workspace" @@ -118,9 +118,6 @@ def test_get_postgis_datastore_valid( status=200, ) result = geoserver.get_postgis_datastore(WORKSPACE, STORE) - assert len(rsps.calls) == 1 - # FIXME: I think the geoserver rest endpoint is wrong, might be a problem with the conftest.py stuff. - # assert rsps.calls[0].request.url == geoserver.rest_endpoints.datastore(WORKSPACE, STORE) assert json.loads(str(result)) == pg_payload @@ -137,7 +134,6 @@ def test_get_postgis_datastore_not_found(geoserver: GeoServerCloud) -> None: not_existing_datastore = geoserver.get_postgis_datastore( WORKSPACE, datastore_name ) - assert len(rsps.calls) == 1 assert not_existing_datastore is None diff --git a/tests/test_feature_type.py b/tests/test_feature_type.py index 4ddf20e..74d0ac3 100644 --- a/tests/test_feature_type.py +++ b/tests/test_feature_type.py @@ -3,7 +3,7 @@ import pytest import responses -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud # TODO: add tests for # - geoservercloud.get_featuretypes() diff --git a/tests/test_gwc.py b/tests/test_gwc.py index 2b1b26c..91ea7cb 100644 --- a/tests/test_gwc.py +++ b/tests/test_gwc.py @@ -1,6 +1,6 @@ import responses -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud WORKSPACE = "test_workspace" LAYER = "test_layer" diff --git a/tests/test_layer_group.py b/tests/test_layer_group.py index 81fb0ac..c575d9b 100644 --- a/tests/test_layer_group.py +++ b/tests/test_layer_group.py @@ -3,7 +3,7 @@ import pytest import responses -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud from tests.conftest import GEOSERVER_URL LAYER_GROUP = "test_layer_group" diff --git a/tests/test_role.py b/tests/test_role.py index 9633655..4d3068e 100644 --- a/tests/test_role.py +++ b/tests/test_role.py @@ -1,6 +1,6 @@ import responses -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud def test_create_role(geoserver: GeoServerCloud) -> None: diff --git a/tests/test_style.py b/tests/test_style.py index d844416..cf0e1f2 100644 --- a/tests/test_style.py +++ b/tests/test_style.py @@ -3,7 +3,7 @@ import pytest import responses -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud from geoservercloud.models import Styles from tests.conftest import GEOSERVER_URL @@ -36,7 +36,6 @@ def test_get_styles_no_workspace(geoserver: GeoServerCloud): assert result == ["style1", "style2"] -@responses.activate def test_get_styles_with_workspace(geoserver: GeoServerCloud): workspace_name = "test_workspace" with responses.RequestsMock() as rsps: diff --git a/tests/test_user.py b/tests/test_user.py index c7b12ab..090d8d1 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -1,7 +1,7 @@ import responses import responses.matchers -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud TEST_USER = "test_user" diff --git a/tests/test_wfs.py b/tests/test_wfs.py index 79c75c1..02a1dbd 100644 --- a/tests/test_wfs.py +++ b/tests/test_wfs.py @@ -1,6 +1,6 @@ import responses -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud from tests.conftest import GEOSERVER_URL WORKSPACE = "test_workspace" diff --git a/tests/test_wms.py b/tests/test_wms.py index 9f2977b..f1aadbc 100644 --- a/tests/test_wms.py +++ b/tests/test_wms.py @@ -1,6 +1,6 @@ import responses -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud from tests.conftest import GEOSERVER_URL WORKSPACE = "test_workspace" diff --git a/tests/test_workspace.py b/tests/test_workspace.py index 41de135..a2d28bf 100644 --- a/tests/test_workspace.py +++ b/tests/test_workspace.py @@ -1,7 +1,7 @@ import responses from responses import matchers -from geoservercloud.geoservercloud import GeoServerCloud +from geoservercloud import GeoServerCloud from tests.conftest import GEOSERVER_URL