Skip to content

Commit

Permalink
Merge pull request #4003 from open-formulieren/issue/objects-api-chec…
Browse files Browse the repository at this point in the history
…k-config

Fix config checks for Objects API plugin
  • Loading branch information
sergei-maertens authored Mar 21, 2024
2 parents 63ab6e5 + 15c4682 commit d6d682c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/openforms/registrations/contrib/objects_api/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@

def check_objects_service():
with get_objects_client() as client:
client.get("objects", params={"pageSize": 1})
resp = client.get("objects", params={"pageSize": 1})
resp.raise_for_status()
if not 200 <= resp.status_code < 300:
raise InvalidPluginConfiguration(_("Missing API credentials"))


def check_objecttypes_service():
with get_objecttypes_client() as client:
client.get("objecttypes", params={"pageSize": 1})
resp = client.get("objecttypes", params={"pageSize": 1})
resp.raise_for_status()
if not 200 <= resp.status_code < 300:
raise InvalidPluginConfiguration(_("Missing API credentials"))


def check_documents_service():
with get_documents_client() as client:
client.get("enkelvoudiginformatieobjecten")
resp = client.get("enkelvoudiginformatieobjecten")
resp.raise_for_status()


def check_config():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_no_objecttypes_service_configured(self, m: requests_mock.Mocker):
plugin.check_config()

@requests_mock.Mocker()
def test_objects_service_misconfigured(self, m):
def test_objects_service_misconfigured_connection_error(self, m):
m.get(
"https://objects.example.com/api/v1/objects?pageSize=1",
exc=requests.ConnectionError,
Expand All @@ -87,6 +87,43 @@ def test_objects_service_misconfigured(self, m):
with self.assertRaises(InvalidPluginConfiguration):
plugin.check_config()

@requests_mock.Mocker()
def test_objects_service_misconfigured_http_error(self, m):
m.get(
"https://objects.example.com/api/v1/objects?pageSize=1",
status_code=400,
)
plugin = ObjectsAPIRegistration(PLUGIN_IDENTIFIER)

with self.assertRaises(InvalidPluginConfiguration):
plugin.check_config()

@requests_mock.Mocker()
def test_objects_service_misconfigured_redirect(self, m):
m.get(
"https://objects.example.com/api/v1/objects?pageSize=1",
status_code=302,
)
plugin = ObjectsAPIRegistration(PLUGIN_IDENTIFIER)

with self.assertRaises(InvalidPluginConfiguration):
plugin.check_config()

@requests_mock.Mocker()
def test_objecttypes_service_misconfigured_redirect(self, m):
m.get(
"https://objects.example.com/api/v1/objects?pageSize=1",
json={"results": []},
)
m.get(
"https://objecttypes.example.com/api/v1/objecttypes?pageSize=1",
status_code=302,
)
plugin = ObjectsAPIRegistration(PLUGIN_IDENTIFIER)

with self.assertRaises(InvalidPluginConfiguration):
plugin.check_config()

@requests_mock.Mocker()
def test_no_documents_service_configured(self, m):
self.config.drc_service = None
Expand Down

0 comments on commit d6d682c

Please sign in to comment.