Skip to content

Commit

Permalink
mocking tests ...
Browse files Browse the repository at this point in the history
  • Loading branch information
john-herholz-dt committed Feb 19, 2024
1 parent b2dc06a commit 7a8cdf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
9 changes: 3 additions & 6 deletions webservice/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright 2020 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import json

from requests import PreparedRequest, Response, Session
import requests
from requests import PreparedRequest, Session

from odoo.tests.common import HttpCase, tagged

Expand Down Expand Up @@ -36,8 +36,5 @@ def _request_handler(cls, s: Session, r: PreparedRequest, /, **kw):
if r.url.startswith("http://demo.localhost.odoo") or r.url.startswith(
"https://custom.url"
):
r = Response()
r.status_code = 200
r._content = json.dumps({})
return r
return requests.Session.send(s, r, **kw)
return super()._request_handler(s, r, **kw)
16 changes: 8 additions & 8 deletions webservice/tests/test_webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_auth_validation(self):
def test_web_service_get(self):
responses.add(responses.GET, self.url, body="{}")
result = self.webservice.call("get")
self.assertEqual(result, "{}")
self.assertEqual(result, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
Expand All @@ -93,7 +93,7 @@ def test_web_service_get(self):
def test_web_service_post(self):
responses.add(responses.POST, self.url, body="{}")
result = self.webservice.call("post", data="demo_response")
self.assertEqual(result, "{}")
self.assertEqual(result, b"{}")
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
)
Expand All @@ -103,7 +103,7 @@ def test_web_service_post(self):
def test_web_service_put(self):
responses.add(responses.PUT, self.url, body="{}")
result = self.webservice.call("put", data="demo_response")
self.assertEqual(result, "{}")
self.assertEqual(result, b"{}")
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
)
Expand All @@ -116,7 +116,7 @@ def test_web_service_backend_username(self):
)
responses.add(responses.GET, self.url, body="{}")
result = self.webservice.call("get")
self.assertEqual(result, "{}")
self.assertEqual(result, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
Expand All @@ -131,7 +131,7 @@ def test_web_service_username(self):
)
responses.add(responses.GET, self.url, body="{}")
result = self.webservice.call("get", auth=("user2", "pass2"))
self.assertEqual(result, "{}")
self.assertEqual(result, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
Expand All @@ -146,7 +146,7 @@ def test_web_service_backend_api_key(self):
)
responses.add(responses.POST, self.url, body="{}")
result = self.webservice.call("post")
self.assertEqual(result, "{}")
self.assertEqual(result, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
Expand All @@ -171,7 +171,7 @@ def test_web_service_call_args(self):
result = self.webservice.call(
"post", url=url, headers={"demo_header": "HEADER"}
)
self.assertEqual(result, "{}")
self.assertEqual(result, b"{}")
self.assertEqual(len(responses.calls), 1)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
Expand All @@ -186,7 +186,7 @@ def test_web_service_call_args(self):
url_params={"endpoint": "custom/path"},
headers={"demo_header": "HEADER"},
)
self.assertEqual(result, "{}")
self.assertEqual(result, b"{}")
self.assertEqual(len(responses.calls), 2)
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
Expand Down

0 comments on commit 7a8cdf2

Please sign in to comment.