Skip to content

Commit

Permalink
[maykinmedia/open-producten#38] add client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Floris272 committed Oct 25, 2024
1 parent b81e7f9 commit b66745c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/openforms/contrib/open_producten/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get_open_producten_client,
)
from openforms.contrib.open_producten.models import OpenProductenConfig
from openforms.products.tests.factories import ProductFactory


class TestOpenProductenClient(TestCase):
Expand Down Expand Up @@ -79,3 +80,46 @@ def test_get_open_producten_client_with_service(self):

client = get_open_producten_client()
self.assertEqual(client.base_url, "http://test/")

def test_product_type_fields(self):
product = ProductFactory()
self.requests_mock.get(
json={
"count": 1,
"next": None,
"previous": None,
"results": [
{
"id": "d4fd8fb8-8b7a-45bf-8b93-969c23573af9",
"name": "text",
"description": "text",
"type": "textfield",
"is_required": None,
"choices": [],
}
],
},
status_code=200,
url=f"https://test/producttypes/{product.uuid}/fields",
)

fields = self.client.get_product_type_fields(product.uuid)

self.assertEqual(len(fields), 1)

field = fields[0]

self.assertEqual(field.name, "text")
self.assertEqual(field.type, "textfield")

def test_get_product_type_fields_with_request_exception(self):
product = ProductFactory()

self.requests_mock.get(
status_code=404,
json={"error": "not found"},
url=f"https://test/producttypes/{product.uuid}/fields",
)

with self.assertRaises(requests.RequestException):
self.client.get_product_type_fields(product.uuid)
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def test_generate_configuration_with_radio(self):
},
)

def test_generate_form_configuration_with_unknown_type(self):
field = _create_field(id=uuid4(), type="unknown")

with self.assertRaisesMessage(ValidationError, "Unknown field type unknown"):
_generate_configuration([field])

@patch("openforms.contrib.open_producten.generate_form.get_open_producten_client")
def test_generate_form(self, mock_get_client):

Expand Down

0 comments on commit b66745c

Please sign in to comment.