diff --git a/src/geoserverx/cli/cli.py b/src/geoserverx/cli/cli.py index a65ee84..5ad2c90 100644 --- a/src/geoserverx/cli/cli.py +++ b/src/geoserverx/cli/cli.py @@ -446,6 +446,7 @@ def geofence_rules( else: typer.echo("Async support will be shortly") + # get geofence rule @SyncGeoServerX.exception_handler @app.command(help="Get geofence rule in the Geoserver") @@ -469,4 +470,4 @@ def geofence_rule( else: print(result) else: - typer.echo("Async support will be shortly") \ No newline at end of file + typer.echo("Async support will be shortly") diff --git a/src/geoserverx/models/geofence.py b/src/geoserverx/models/geofence.py index 1a6aab3..4096e32 100644 --- a/src/geoserverx/models/geofence.py +++ b/src/geoserverx/models/geofence.py @@ -1,5 +1,6 @@ +from typing import List, Literal, Optional + from pydantic import BaseModel -from typing import List, Optional, Literal class Attribute(BaseModel): diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index 6b78870..23a5c28 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -393,36 +393,38 @@ def test_get_all_layer_groups_NetworkError(respx_mock): # Test - all_geofence_rules def test_all_geofence_rules_validation(bad_all_geofence_rules_connection, respx_mock): respx_mock.get(f"{baseUrl}about/status.json").mock( - return_value=httpx.Response(200, json={ - 'statuss': {'status': [{'name': 'geofence'}]} - }) - ) - respx_mock.get(f"{baseUrl}geofence/rules/", headers={'Accept': "application/json"}).mock( - return_value=httpx.Response(404, json=bad_all_geofence_rules_connection) + return_value=httpx.Response( + 200, json={"statuss": {"status": [{"name": "geofence"}]}} + ) ) + respx_mock.get( + f"{baseUrl}geofence/rules/", headers={"Accept": "application/json"} + ).mock(return_value=httpx.Response(404, json=bad_all_geofence_rules_connection)) result = runner.invoke(app, ["geofence-rules"]) assert "404" in result.stdout def test_all_geofence_rules_success(good_all_geofence_rules_connection, respx_mock): respx_mock.get(f"{baseUrl}about/status.json").mock( - return_value=httpx.Response(200, json={ - 'statuss': {'status': [{'name': 'geofence'}]} - }) - ) - respx_mock.get(f"{baseUrl}geofence/rules/", headers={'Accept': "application/json"}).mock( - return_value=httpx.Response(200, json=good_all_geofence_rules_connection) + return_value=httpx.Response( + 200, json={"statuss": {"status": [{"name": "geofence"}]}} + ) ) + respx_mock.get( + f"{baseUrl}geofence/rules/", headers={"Accept": "application/json"} + ).mock(return_value=httpx.Response(200, json=good_all_geofence_rules_connection)) result = runner.invoke(app, ["geofence-rules"]) assert "2" in result.stdout def test_all_geofence_rules_NetworkError(respx_mock): respx_mock.get(f"{baseUrl}about/status.json").mock( - return_value=httpx.Response(200, json={ - 'statuss': {'status': [{'name': 'geofence'}]} - }) + return_value=httpx.Response( + 200, json={"statuss": {"status": [{"name": "geofence"}]}} + ) ) - respx_mock.get(f"{baseUrl}geofence/rules/", headers={'Accept': "application/json"}).mock(side_effect=httpx.ConnectError) + respx_mock.get( + f"{baseUrl}geofence/rules/", headers={"Accept": "application/json"} + ).mock(side_effect=httpx.ConnectError) result = runner.invoke(app, ["geofence-rules"]) assert "Error in connecting to Geoserver" in result.stdout diff --git a/tests/conftest.py b/tests/conftest.py index e9fbfb3..a5cb7ca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -671,140 +671,141 @@ def networkbad_layer_groups_connection() -> dict: item = {"code": 503, "response": "Geoserver unavailable"} return item + @pytest.fixture def good_all_geofence_rules_connection() -> dict: item = { - "count": 2, - "rules": [ - { - "id": 2, - "priority": 0, - "userName": None, - "roleName": "ROLE_ANONYMOUS", - "addressRange": None, - "workspace": "ne", - "layer": "ne_10m_admin_0_countries", - "service": None, - "request": None, - "subfield": None, - "access": "ALLOW", - "limits": None, - "layerDetails": { - "layerType": "VECTOR", - "defaultStyle": None, - "cqlFilterRead": "INCOME_GRP = '4. Lower middle income'", - "cqlFilterWrite": None, - "allowedArea": None, - "spatialFilterType": "INTERSECT", - "catalogMode": None, - "allowedStyles": [], - "attributes": [ - { - "name": "FCLASS_SA", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "NAME_NL", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "FCLASS_PK", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "ADM0_DIF", - "dataType": "java.lang.Integer", - "accessType": "NONE" - }, - { - "name": "ADM0_A3_ID", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "WOE_ID_EH", - "dataType": "java.lang.Integer", - "accessType": "NONE" - }, - { - "name": "FCLASS_TW", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "ADM0_A3", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "FCLASS_US", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "ISO_A2_EH", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "ADM0_A3_IT", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "FCLASS_NP", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "ISO_N3", - "dataType": "java.lang.String", - "accessType": "NONE" - } - ] - } - }, - { - "id": 1, - "priority": 1, - "userName": None, - "roleName": "ADMIN", - "addressRange": None, - "workspace": "ne", - "layer": "ne_10m_admin_0_countries", - "service": None, - "request": None, - "subfield": None, - "access": "ALLOW", - "limits": None, - "layerDetails": { - "layerType": "VECTOR", - "defaultStyle": "generic", - "cqlFilterRead": "ADMIN = 'India'", - "cqlFilterWrite": None, - "allowedArea": None, - "spatialFilterType": "INTERSECT", - "catalogMode": None, - "allowedStyles": [], - "attributes": [ - { - "name": "FCLASS_MA", - "dataType": "java.lang.String", - "accessType": "NONE" - }, - { - "name": "ABBREV", - "dataType": "java.lang.String", - "accessType": "NONE" - } - ] - } - } - ] -} + "count": 2, + "rules": [ + { + "id": 2, + "priority": 0, + "userName": None, + "roleName": "ROLE_ANONYMOUS", + "addressRange": None, + "workspace": "ne", + "layer": "ne_10m_admin_0_countries", + "service": None, + "request": None, + "subfield": None, + "access": "ALLOW", + "limits": None, + "layerDetails": { + "layerType": "VECTOR", + "defaultStyle": None, + "cqlFilterRead": "INCOME_GRP = '4. Lower middle income'", + "cqlFilterWrite": None, + "allowedArea": None, + "spatialFilterType": "INTERSECT", + "catalogMode": None, + "allowedStyles": [], + "attributes": [ + { + "name": "FCLASS_SA", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "NAME_NL", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "FCLASS_PK", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "ADM0_DIF", + "dataType": "java.lang.Integer", + "accessType": "NONE", + }, + { + "name": "ADM0_A3_ID", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "WOE_ID_EH", + "dataType": "java.lang.Integer", + "accessType": "NONE", + }, + { + "name": "FCLASS_TW", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "ADM0_A3", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "FCLASS_US", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "ISO_A2_EH", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "ADM0_A3_IT", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "FCLASS_NP", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "ISO_N3", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + ], + }, + }, + { + "id": 1, + "priority": 1, + "userName": None, + "roleName": "ADMIN", + "addressRange": None, + "workspace": "ne", + "layer": "ne_10m_admin_0_countries", + "service": None, + "request": None, + "subfield": None, + "access": "ALLOW", + "limits": None, + "layerDetails": { + "layerType": "VECTOR", + "defaultStyle": "generic", + "cqlFilterRead": "ADMIN = 'India'", + "cqlFilterWrite": None, + "allowedArea": None, + "spatialFilterType": "INTERSECT", + "catalogMode": None, + "allowedStyles": [], + "attributes": [ + { + "name": "FCLASS_MA", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + { + "name": "ABBREV", + "dataType": "java.lang.String", + "accessType": "NONE", + }, + ], + }, + }, + ], + } return item @@ -822,7 +823,22 @@ def networkbad_all_geofence_rules_connection() -> dict: @pytest.fixture def good_new_geofence_rule_connection() -> dict: - item = {"Rule":{"priority":3,"userName":None,"roleName":"ROLE_AUTHENTICATED","addressRange":None,"workspace":"*","layer":"ne","service":"GWC","request":None,"subfield":None,"access":"ALLOW","limits":None,"layerDetails":None}} + item = { + "Rule": { + "priority": 3, + "userName": None, + "roleName": "ROLE_AUTHENTICATED", + "addressRange": None, + "workspace": "*", + "layer": "ne", + "service": "GWC", + "request": None, + "subfield": None, + "access": "ALLOW", + "limits": None, + "layerDetails": None, + } + } return item