Skip to content

Commit

Permalink
[#8] Update API endpoint for forms
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Jun 26, 2024
1 parent 7008371 commit 81e0207
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions openformsclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def is_healthy(self) -> Tuple[bool, str]:
try:
# We do a head request to actually hit a protected endpoint without
# getting a whole bunch of data.
response = self._request("head", "forms")
response = self._request("head", "public/forms")
response.raise_for_status()
return (True, "")
except HTTPError as e:
# If something is wrong, we might get more information from the
# error message provided by Open Forms.
try:
response = self._request("get", "forms")
response = self._request("get", "public/forms")
data = response.json()
message = (
data.get("detail", data.get("title"))
Expand All @@ -62,7 +62,7 @@ def get_forms(self) -> list:
:returns: The API response content as Python object.
"""
response = self._request("get", "forms")
response = self._request("get", "public/forms")
response.raise_for_status()

return response.json()
Expand Down
18 changes: 9 additions & 9 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@requests_mock.Mocker()
class ClientTests(TestCase):
def setUp(self):
self.api_root = "https://example.com/api/v1/"
self.api_root = "https://example.com/api/v2/"
self.api_token = "token"
self.client_timeout = 2
self.client = Client(self.api_root, self.api_token, self.client_timeout)
Expand All @@ -22,7 +22,7 @@ def test_has_config(self, m):

def test_is_healthy(self, m):
m.head(
f"{self.api_root}forms",
f"{self.api_root}public/forms",
request_headers={"Authorization": f"Token {self.api_token}"},
)

Expand All @@ -31,17 +31,17 @@ def test_is_healthy(self, m):
self.assertEqual(msg, "")

def test_is_healthy_invalid_response(self, m):
m.head(f"{self.api_root}forms", status_code=500) # Doesn't really matter
m.get(f"{self.api_root}forms", text="Woops")
m.head(f"{self.api_root}public/forms", status_code=500) # Doesn't really matter
m.get(f"{self.api_root}public/forms", text="Woops")

health, msg = self.client.is_healthy()
self.assertFalse(health)
self.assertEqual(msg, "Server did not return a valid response (HTTP 500).")

def test_is_healthy_invalid_token(self, m):
m.head(f"{self.api_root}forms", status_code=401)
m.head(f"{self.api_root}public/forms", status_code=401)
m.get(
f"{self.api_root}forms",
f"{self.api_root}public/forms",
json={
"type": "https://example.com/fouten/AuthenticationFailed/",
"code": "authentication_failed",
Expand All @@ -57,13 +57,13 @@ def test_is_healthy_invalid_token(self, m):
self.assertEqual(msg, "Ongeldige token.")

def test_get_forms(self, m):
m.get(f"{self.api_root}forms", json=[])
m.get(f"{self.api_root}public/forms", json=[])

result = self.client.get_forms()
self.assertListEqual(result, [])

def test_get_forms_with_error(self, m):
m.get(f"{self.api_root}forms", status_code=401)
m.get(f"{self.api_root}public/forms", status_code=401)

with self.assertRaises(HTTPError):
self.client.get_forms()
Expand All @@ -85,7 +85,7 @@ def test_request_uses_configured_timeout(self, m):
self.client.get_form("myform")
mock_request.assert_called_with(
"get",
"https://example.com/api/v1/forms/myform",
"https://example.com/api/v2/forms/myform",
headers={"Authorization": "Token token"},
timeout=2,
)
2 changes: 1 addition & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setUp(self):

def _prepare_mock(self, m):
m.get(
f"{self.config.api_root}forms",
f"{self.config.api_root}public/forms",
json=[
{
"uuid": "1b0d0675-2caf-48e8-beda-c32c6732b63c",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_get_form_choices_without_config(self, m):

def test_get_form_choices_without_client(self, m):
m.get(
f"{self.config.api_root}forms",
f"{self.config.api_root}public/forms",
json=[
{
"uuid": "1b0d0675-2caf-48e8-beda-c32c6732b63c",
Expand All @@ -49,7 +49,7 @@ def test_get_form_choices_without_client(self, m):

def test_get_form_choices_with_client(self, m):
m.get(
f"{self.config.api_root}forms",
f"{self.config.api_root}public/forms",
json=[
{
"uuid": "1b0d0675-2caf-48e8-beda-c32c6732b63c",
Expand All @@ -76,7 +76,7 @@ def test_get_form_choices_with_client(self, m):

def test_get_form_choices_use_uuids(self, m):
m.get(
f"{self.config.api_root}forms",
f"{self.config.api_root}public/forms",
json=[
{
"uuid": "1b0d0675-2caf-48e8-beda-c32c6732b63c",
Expand Down

0 comments on commit 81e0207

Please sign in to comment.