mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-18 07:32:04 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
|||
from . import test_default_binder
|
||||
from . import test_related_action_binding
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
# Copyright 2013-2017 Camptocamp SA
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from odoo.addons.component.tests.common import TransactionComponentCase
|
||||
|
||||
|
||||
class TestDefaultBinder(TransactionComponentCase):
|
||||
"""Test the default binder implementation using Components"""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
# create our backend, in case of components,
|
||||
# the version would not be required
|
||||
self.backend_record = self.env["test.backend"].create({})
|
||||
|
||||
def test_default_binder(self):
|
||||
"""Small scenario with the default binder"""
|
||||
# create a work context with the model we want to work with
|
||||
with self.backend_record.work_on("connector.test.binding") as work:
|
||||
# get our binder component (for the model in whe work context)
|
||||
self.binder = work.component(usage="binder")
|
||||
test_record = self.env["connector.test.record"].create({})
|
||||
test_binding = self.env["connector.test.binding"].create(
|
||||
{"backend_id": self.backend_record.id, "odoo_id": test_record.id}
|
||||
)
|
||||
|
||||
# bind the test binding to external id = 99
|
||||
self.binder.bind(99, test_binding)
|
||||
# find the odoo binding bound to external record 99
|
||||
binding = self.binder.to_internal(99)
|
||||
self.assertEqual(binding, test_binding)
|
||||
# find the odoo record bound to external record 99
|
||||
record = self.binder.to_internal(99, unwrap=True)
|
||||
self.assertEqual(record, test_record)
|
||||
# find the external record bound to odoo binding
|
||||
external_id = self.binder.to_external(test_binding)
|
||||
self.assertEqual(external_id, 99)
|
||||
# find the external record bound to odoo record
|
||||
external_id = self.binder.to_external(test_record, wrap=True)
|
||||
self.assertEqual(external_id, 99)
|
||||
self.assertEqual(self.binder.unwrap_model(), "connector.test.record")
|
||||
# unwrapping the binding should give the same binding
|
||||
self.assertEqual(self.binder.unwrap_binding(test_binding), test_record)
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
# Copyright 2013-2017 Camptocamp SA
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
from odoo.addons.component.tests.common import TransactionComponentCase
|
||||
|
||||
|
||||
class TestRelatedActionBinding(TransactionComponentCase):
|
||||
"""Test Related Actions with Bindings"""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.backend_record = self.env["test.backend"].create({})
|
||||
|
||||
def test_unwrap_binding(self):
|
||||
"""Call the unwrap binding related action"""
|
||||
binding = self.env["connector.test.binding"].create(
|
||||
{"backend_id": self.backend_record.id, "external_id": 99}
|
||||
)
|
||||
|
||||
job = binding.with_delay().job_related_action_unwrap()
|
||||
db_job = job.db_record()
|
||||
action = db_job.open_related_action()
|
||||
expected = {
|
||||
"name": mock.ANY,
|
||||
"type": "ir.actions.act_window",
|
||||
"view_type": "form",
|
||||
"view_mode": "form",
|
||||
"res_id": binding.odoo_id.id,
|
||||
"res_model": "connector.test.record",
|
||||
}
|
||||
self.assertEqual(action, expected)
|
||||
|
||||
def test_unwrap_binding_direct_binding(self):
|
||||
"""Call the unwrap binding related action"""
|
||||
binding = self.env["no.inherits.binding"].create(
|
||||
{"backend_id": self.backend_record.id, "external_id": 99}
|
||||
)
|
||||
|
||||
job = binding.with_delay().job_related_action_unwrap()
|
||||
db_job = job.db_record()
|
||||
action = db_job.open_related_action()
|
||||
expected = {
|
||||
"name": mock.ANY,
|
||||
"type": "ir.actions.act_window",
|
||||
"view_type": "form",
|
||||
"view_mode": "form",
|
||||
"res_id": binding.id,
|
||||
"res_model": "no.inherits.binding",
|
||||
}
|
||||
self.assertEqual(action, expected)
|
||||
|
||||
def test_unwrap_binding_not_exists(self):
|
||||
"""Call the related action on the model on non-existing record"""
|
||||
binding = self.env["connector.test.binding"].create(
|
||||
{"backend_id": self.backend_record.id, "external_id": 99}
|
||||
)
|
||||
|
||||
job = binding.with_delay().job_related_action_unwrap()
|
||||
|
||||
db_job = job.db_record()
|
||||
|
||||
binding.unlink()
|
||||
|
||||
with self.assertRaisesRegex(UserError, "No action available for this job"):
|
||||
db_job.open_related_action()
|
||||
Loading…
Add table
Add a link
Reference in a new issue