Skip to content

Commit

Permalink
[IMP] webservice: combine the url with collection's url
Browse files Browse the repository at this point in the history
when a call is made with just a path, combine it with the collection's url
  • Loading branch information
gurneyalex committed Mar 4, 2024
1 parent 19ac2ed commit 9bc0dc6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
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 = self.collection.url + url
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

0 comments on commit 9bc0dc6

Please sign in to comment.