Skip to content

Commit

Permalink
linting done
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnaglodha committed Sep 4, 2024
1 parent 8ec71f2 commit b1d9df1
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 150 deletions.
3 changes: 2 additions & 1 deletion src/geoserverx/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -469,4 +470,4 @@ def geofence_rule(
else:
print(result)
else:
typer.echo("Async support will be shortly")
typer.echo("Async support will be shortly")
3 changes: 2 additions & 1 deletion src/geoserverx/models/geofence.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List, Literal, Optional

from pydantic import BaseModel
from typing import List, Optional, Literal


class Attribute(BaseModel):
Expand Down
34 changes: 18 additions & 16 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
280 changes: 148 additions & 132 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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


Expand Down

0 comments on commit b1d9df1

Please sign in to comment.