-
-
Notifications
You must be signed in to change notification settings - Fork 313
/
Copy pathtest_backend_process.py
82 lines (71 loc) · 2.76 KB
/
test_backend_process.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
# Copyright 2020 ACSONE
# @author: Simone Orsi <simahawk@gmail.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
import base64
from odoo import fields
from odoo.exceptions import UserError
from odoo.tools import mute_logger
from .common import EDIBackendCommonComponentRegistryTestCase
from .fake_components import FakeInputProcess
class EDIBackendTestCase(EDIBackendCommonComponentRegistryTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls._build_components(
# TODO: test all components lookup
cls,
FakeInputProcess,
)
vals = {
"model": cls.partner._name,
"res_id": cls.partner.id,
"exchange_file": base64.b64encode(b"1234"),
}
cls.record = cls.backend.create_record("test_csv_input", vals)
def setUp(self):
super().setUp()
FakeInputProcess.reset_faked()
def test_process_record(self):
self.record.write({"edi_exchange_state": "input_received"})
now = fields.Datetime.now()
self.record.action_exchange_process()
self.assertTrue(FakeInputProcess.check_called_for(self.record))
self.assertRecordValues(
self.record, [{"edi_exchange_state": "input_processed"}]
)
self.record.refresh()
self.assertAlmostEqual(
(self.record.exchanged_on - now).total_seconds(),
0, places=2)
def test_process_record_with_error(self):
self.record.write({"edi_exchange_state": "input_received"})
self.record._set_file_content("TEST %d" % self.record.id)
self.record.with_context(
test_break_process="OOPS! Something went wrong :("
).action_exchange_process()
self.assertTrue(FakeInputProcess.check_called_for(self.record))
self.assertRecordValues(
self.record,
[
{
"edi_exchange_state": "input_processed_error",
}
],
)
self.assertIn("OOPS! Something went wrong :(", self.record.exchange_error)
@mute_logger("odoo.models.unlink")
def test_process_no_file_record(self):
self.record.write({"edi_exchange_state": "input_received"})
self.record.exchange_file = False
with self.assertRaises(UserError):
self.record.action_exchange_process()
def test_process_outbound_record(self):
vals = {
"model": self.partner._name,
"res_id": self.partner.id,
}
record = self.backend.create_record("test_csv_output", vals)
record._set_file_content("TEST %d" % record.id)
with self.assertRaises(UserError):
record.action_exchange_process()
# TODO: test ack file are processed