Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] webservice: combine the url with collection's url #36

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions webservice/components/request_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ def _get_headers_for_api_key(self, **kw):

def _get_url(self, url=None, url_params=None, **kwargs):
if not url:
# TODO: if url is given, we should validate the domain
# to avoid abusing a webservice backend for different calls.
url = self.collection.url
elif not url.startswith(self.collection.url):
if not url.startswith("http"):
url = f"{self.collection.url.rstrip('/')}/{url.lstrip('/')}"
else:
# TODO: if url is given, we should validate the domain
# to avoid abusing a webservice backend for different calls.
pass

url_params = url_params or kwargs
return url.format(**url_params)
22 changes: 22 additions & 0 deletions webservice/tests/test_webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ def test_web_service_get(self):
responses.calls[0].request.headers["Content-Type"], "application/xml"
)

@responses.activate
def test_web_service_get_url_combine(self):
endpoint = "api/test"
responses.add(responses.GET, self.url + endpoint, body="{}")
result = self.webservice.call("get", url="api/test")
self.assertEqual(result, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
)

@responses.activate
def test_web_service_get_url_combine_full_url(self):
endpoint = "api/test"
responses.add(responses.GET, self.url + endpoint, body="{}")
result = self.webservice.call("get", url="http://localhost.demo.odoo/api/test")
self.assertEqual(result, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
)

@responses.activate
def test_web_service_post(self):
responses.add(responses.POST, self.url, body="{}")
Expand Down
Loading