[IMP] *: add generic make_jsonrpc method in tests
*: bus, crm_livechat, crm_mail_plugin, im_livechat, payment, payment_demo, pos_online_payment, test_discuss_full, test_mail_full, tests, website_livechat, website_sale. Several python tests have their own way to make jsonrpc requests. This PR adds a generic `make_jsonrpc_request` method to the `HttpCase` in order to provide a generic way to do so. At the same time, calls to `_open_livechat_channel` are removed in favor of jsonrpc request to `get_session`. This makes the tests more realistics (some incoherences were present like passing `country_id` to the open channel method while the user country id is not set...) Finally, this will ease the diff in the PR introducing livechat visitors as mail guests. part of task-3332628 closes odoo/odoo#130036 Related: odoo/enterprise#44840 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
@@ -15,7 +15,7 @@ class TestCrmMailPlugin(TestMailPluginControllerCommon):
|
||||
{"name": "Partner 2"},
|
||||
])
|
||||
|
||||
result = self._make_rpc_call("/mail_plugin/partner/get", {"partner_id": partner.id})
|
||||
result = self.make_jsonrpc_request("/mail_plugin/partner/get", {"partner_id": partner.id})
|
||||
|
||||
self.assertNotIn("leads", result,
|
||||
msg="The user has no access to crm.lead, the leads section should not be visible")
|
||||
@@ -27,7 +27,7 @@ class TestCrmMailPlugin(TestMailPluginControllerCommon):
|
||||
{"name": "Lead Partner 2", "partner_id": partner_2.id},
|
||||
])
|
||||
|
||||
result = self._make_rpc_call("/mail_plugin/partner/get", {"partner_id": partner.id})
|
||||
result = self.make_jsonrpc_request("/mail_plugin/partner/get", {"partner_id": partner.id})
|
||||
|
||||
self.assertIn(
|
||||
"leads",
|
||||
@@ -71,7 +71,7 @@ class TestCrmMailPlugin(TestMailPluginControllerCommon):
|
||||
'email_subject': 'test subject',
|
||||
}
|
||||
|
||||
result = self._make_rpc_call('/mail_plugin/lead/create', params)
|
||||
result = self.make_jsonrpc_request('/mail_plugin/lead/create', params)
|
||||
|
||||
# Check that the created lead record has the correct company and return the lead_id
|
||||
self.assertIn(
|
||||
@@ -87,27 +87,3 @@ class TestCrmMailPlugin(TestMailPluginControllerCommon):
|
||||
company_b,
|
||||
msg='The created record should belong to company_B',
|
||||
)
|
||||
|
||||
def _make_rpc_call(self, url, params):
|
||||
"""
|
||||
Makes an RPC call to the specified URL with the given parameters, and returns the 'result' key from the response.
|
||||
|
||||
:param params (dict): A dictionary containing the parameters to send in the RPC call.
|
||||
:param url (str): The URL to send the RPC call to.
|
||||
:return (dict): The 'result' key from the response.
|
||||
"""
|
||||
|
||||
data = {
|
||||
'id': 0,
|
||||
'jsonrpc': '2.0',
|
||||
'method': 'call',
|
||||
'params': params,
|
||||
}
|
||||
|
||||
response = self.url_open(
|
||||
url,
|
||||
data=json.dumps(data).encode(),
|
||||
headers={'Content-Type': 'application/json'}
|
||||
).json()
|
||||
|
||||
return response['result']
|
||||
|
||||
Reference in New Issue
Block a user