forked from OCA/wms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_scan_anything_service.py
89 lines (69 loc) · 2.91 KB
/
test_scan_anything_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright 2020 Camptocamp SA (http://www.camptocamp.com)
# Copyright 2021 ACSONE SA/NV (http://www.acsone.eu)
# @author Simone Orsi <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.addons.component.core import Component
from .common import CommonCase
from .common_misc import ScanAnythingTestMixin
class ScanAnythingCase(CommonCase, ScanAnythingTestMixin):
def _get_test_handlers(self):
class PartnerFinder(Component):
_name = "shopfloor.scan.partner.handler"
_inherit = "shopfloor.scan.anything.handler"
record_type = "testpartner"
def search(self, identifier):
return (
self.env["res.partner"]
.sudo()
.search([("ref", "=", identifier)], limit=1)
)
@property
def converter(self):
return self._data.partner
def schema(self):
return self._schema._simple_record()
class CurrencyFinder(Component):
_name = "shopfloor.scan.currency.handler"
_inherit = "shopfloor.scan.anything.handler"
record_type = "testcurrency"
def search(self, identifier):
return (
self.env["res.currency"]
.sudo()
.search([("name", "=", identifier)], limit=1)
)
@property
def converter(self):
return lambda record: record.jsonify(
self._data._simple_record_parser(), one=True
)
def schema(self):
return self._schema._simple_record()
return (PartnerFinder, CurrencyFinder)
def test_scan(self):
service = self.get_service("scan_anything")
test_handlers = self._get_test_handlers()
for finder_class in test_handlers:
finder_class._build_component(service.work.components_registry)
handlers = service._scan_handlers()
for handler_cls in test_handlers:
self.assertIn(handler_cls._name, [x._name for x in handlers])
record = self.env.ref("base.res_partner_4").sudo()
record.ref = "1234"
rec_type = "testpartner"
identifier = record.ref
data = record.jsonify(["id", "name"], one=True)
self._test_response_ok(
rec_type, data, identifier, record_types=("testpartner", "testcurrency")
)
record = self.env.ref("base.EUR").sudo()
rec_type = "testcurrency"
identifier = record.name
data = record.jsonify(["id", "name"], one=True)
self._test_response_ok(
rec_type, data, identifier, record_types=("testpartner", "testcurrency")
)
def test_scan_error(self):
self._test_response_ko(
"404-NOTFOUND", record_types=("testpartner", "testcurrency")
)