-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3495 from open-formulieren/refactor/3489-api-clie…
…nt-implementations Refactor API client implementations
- Loading branch information
Showing
98 changed files
with
2,611 additions
and
4,987 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import string | ||
from urllib.parse import quote_plus, urlsplit | ||
|
||
from django.test import SimpleTestCase | ||
|
||
from furl import furl | ||
from hypothesis import assume, example, given, strategies as st | ||
from hypothesis.provisional import domains, urls | ||
|
||
from ..client import is_base_url | ||
|
||
printable_text = st.text(string.printable) | ||
|
||
|
||
class IsBaseUrlTests(SimpleTestCase): | ||
@given(domains()) | ||
def test_domain_without_protocol(self, item: str): | ||
assume(not item.startswith("http://")) | ||
assume(not item.startswith("https://")) | ||
|
||
self.assertFalse(is_base_url(item)) | ||
|
||
@given(st.text(string.printable)) | ||
@example("/some/absolute/path") | ||
def test_random_text_without_protocol(self, item: str): | ||
assume(not item.startswith("http://")) | ||
assume(not item.startswith("https://")) | ||
|
||
try: | ||
is_base = is_base_url(item) | ||
except ValueError: | ||
# furl got something that it can't parse as a URL, and we do want to bubble | ||
# this error up to the caller | ||
pass | ||
else: | ||
self.assertFalse(is_base) | ||
|
||
@given( | ||
st.sampled_from(["https", "http", "ftp", "file"]), | ||
st.lists(printable_text.map(quote_plus)).map("/".join), | ||
) | ||
def test_protocol_but_no_netloc(self, protocol, path): | ||
url = f"{protocol}:///{path}" | ||
|
||
self.assertFalse(is_base_url(url)) | ||
|
||
@given(urls()) | ||
def test_rfc_3986_url(self, url): | ||
assert url.startswith("http://") or url.startswith("https://") | ||
bits = urlsplit(url) | ||
# not allowed for communication between hosts - it's a way to request a dynamically | ||
# allocated port number. | ||
assume(bits.port != 0) | ||
|
||
self.assertTrue(is_base_url(url)) | ||
|
||
@given( | ||
st.sampled_from(["ftp", "file", "madeupthing"]), | ||
domains(), | ||
st.lists(printable_text.map(quote_plus)).map("/".join), | ||
) | ||
def test_non_http_protocol(self, protocol, domain, path): | ||
url = f"{protocol}://{domain}/{path}" | ||
|
||
# we don't really care about the actual protocol, you *could* install a requests | ||
# adapter for non-http(s) | ||
self.assertTrue(is_base_url(url)) | ||
|
||
def test_handle_str_or_furl_instance(self): | ||
example = "https://example.com/foo" | ||
|
||
with self.subTest("raw string"): | ||
self.assertTrue(is_base_url(example)) | ||
|
||
with self.subTest("furl instance string"): | ||
self.assertTrue(is_base_url(furl(example))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
from zeep.client import Client | ||
|
||
from soap.client import build_client | ||
|
||
from .models import JccConfig | ||
|
||
|
||
def get_client() -> Client: | ||
config = JccConfig.get_solo() | ||
assert isinstance(config, JccConfig) | ||
assert config.service is not None | ||
return config.service.build_client() | ||
return build_client(config.service) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/openforms/appointments/contrib/jcc/tests/test_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from unittest.mock import patch | ||
|
||
from django.test import TestCase | ||
|
||
from privates.test import temp_private_root | ||
from zeep.client import Client as ZeepClient | ||
|
||
from simple_certmanager_ext.tests.factories import CertificateFactory | ||
from soap.tests.factories import SoapServiceFactory | ||
|
||
from ..client import get_client | ||
from ..models import JccConfig | ||
from .utils import WSDL | ||
|
||
|
||
@temp_private_root() | ||
class ClientConfigurationTests(TestCase): | ||
@patch("openforms.appointments.contrib.jcc.client.JccConfig.get_solo") | ||
def test_client_transport_supports_mtls(self, m_get_solo): | ||
# Smoke test to check that the service configuration is honoured | ||
client_cert = CertificateFactory.create(with_private_key=True) | ||
config = JccConfig( | ||
service=SoapServiceFactory.build( | ||
url=WSDL, # cheat by passing a file path | ||
client_certificate=client_cert, | ||
) | ||
) | ||
m_get_solo.return_value = config | ||
|
||
client = get_client() | ||
|
||
self.assertIsInstance(client, ZeepClient) | ||
self.assertEqual( | ||
client.transport.session.cert, | ||
(client_cert.public_certificate.path, client_cert.private_key.path), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.