|
1 | 1 | # Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
2 |
| -# Copyright 2023 Camptocamp SA |
3 | 2 | # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
4 | 3 |
|
5 |
| -from ast import literal_eval |
6 |
| - |
7 |
| -from freezegun import freeze_time |
8 |
| - |
9 |
| -from odoo.tests.common import TransactionCase |
10 |
| -from odoo.tools import file_open |
11 |
| - |
12 |
| -# FIXME: all those simple convertion tests should move to lib/wamas/tests and |
13 |
| -# there should be a test that runs the lib tests |
14 |
| - |
15 |
| - |
16 |
| -class TestWamasLib(TransactionCase): |
17 |
| - @classmethod |
18 |
| - def setUpClass(cls): |
19 |
| - super().setUpClass() |
20 |
| - cls.base_wamas_ubl = cls.env["base.wamas.ubl"] |
21 |
| - |
22 |
| - @freeze_time("2023-05-01") |
23 |
| - def _convert_wamas2ubl(self, input_filename, expected_output_filename): |
24 |
| - path = "base_wamas_ubl/tests/samples/" |
25 |
| - with file_open(path + input_filename) as inputfile, file_open( |
26 |
| - path + expected_output_filename |
27 |
| - ) as outputfile: |
28 |
| - str_input = inputfile.read() |
29 |
| - output = "\n".join(self.base_wamas_ubl.wamas2ubl(str_input)) |
30 |
| - expected_output = outputfile.read() |
31 |
| - self.assertEqual(output, expected_output) |
32 |
| - |
33 |
| - def test_convert_wamas2ubl_picking(self): |
34 |
| - input_file = "WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas" |
35 |
| - lst_expected_output = "WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml" |
36 |
| - self._convert_wamas2ubl(input_file, lst_expected_output) |
37 |
| - |
38 |
| - def test_convert_wamas2ubl_reception(self): |
39 |
| - input_file = "WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ.wamas" |
40 |
| - lst_expected_output = "WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ-DESPATCH_ADVICE.xml" |
41 |
| - self._convert_wamas2ubl(input_file, lst_expected_output) |
42 |
| - |
43 |
| - def test_convert_wamas2ubl_return(self): |
44 |
| - input_file = "WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ.wamas" |
45 |
| - lst_expected_output = "WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ-DESPATCH_ADVICE.xml" |
46 |
| - self._convert_wamas2ubl(input_file, lst_expected_output) |
47 |
| - |
48 |
| - @freeze_time("2023-05-01") |
49 |
| - def _convert_ubl2wamas( |
50 |
| - self, input_filename, expected_output_filename, telegram_type |
51 |
| - ): |
52 |
| - path = "base_wamas_ubl/tests/samples/" |
53 |
| - with file_open(path + input_filename) as inputfile, file_open( |
54 |
| - path + expected_output_filename |
55 |
| - ) as outputfile: |
56 |
| - str_input = inputfile.read() |
57 |
| - output = self.base_wamas_ubl.ubl2wamas(str_input, telegram_type) |
58 |
| - expected_output = outputfile.read().strip("\n") |
59 |
| - self.assertEqual(output, expected_output) |
60 |
| - |
61 |
| - def test_convert_ubl2wamas_picking(self): |
62 |
| - input_file = "UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml" |
63 |
| - expected_output = "UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas" |
64 |
| - msg_type = "Picking" |
65 |
| - self._convert_ubl2wamas(input_file, expected_output, msg_type) |
66 |
| - |
67 |
| - def test_convert_ubl2wamas_reception(self): |
68 |
| - input_file = "UBL2WAMAS-SAMPLE_WEAK_WEAP-DESPATCH_ADVICE.xml" |
69 |
| - expected_output = "UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas" |
70 |
| - msg_type = "Reception" |
71 |
| - self._convert_ubl2wamas(input_file, expected_output, msg_type) |
72 |
| - |
73 |
| - def test_convert_ubl2wamas_return(self): |
74 |
| - input_file = "UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml" |
75 |
| - expected_output = "UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas" |
76 |
| - msg_type = "Return" |
77 |
| - self._convert_ubl2wamas(input_file, expected_output, msg_type) |
78 |
| - |
79 |
| - @freeze_time("2023-12-21 04:12:51") |
80 |
| - def test_export_dict2wamas(self): |
81 |
| - input_filename = "DICT2WAMAS-SAMPLE_INPUT.dict" |
82 |
| - expected_output_filename = "DICT2WAMAS-SAMPLE_OUTPUT.wamas" |
83 |
| - path = "base_wamas_ubl/tests/samples/" |
84 |
| - with file_open(path + input_filename) as inputfile, file_open( |
85 |
| - path + expected_output_filename |
86 |
| - ) as outputfile: |
87 |
| - dict_input = literal_eval(inputfile.read()) |
88 |
| - output = self.base_wamas_ubl.dict2wamas(dict_input, "Supplier") |
89 |
| - expected_output = outputfile.read() |
90 |
| - self.assertEqual(output, expected_output) |
91 |
| - |
92 |
| - @freeze_time("2023-12-21 04:12:51") |
93 |
| - def test_get_wamas_type(self): |
94 |
| - input_filename = "CHECKWAMAS-SAMPLE_INPUT.wamas" |
95 |
| - expected_output_filename = "CHECKWAMAS-SAMPLE_OUTPUT.dict" |
96 |
| - path = "base_wamas_ubl/tests/samples/" |
97 |
| - with file_open(path + input_filename) as inputfile, file_open( |
98 |
| - path + expected_output_filename |
99 |
| - ) as outputfile: |
100 |
| - str_input = inputfile.read() |
101 |
| - dict_expected_output = literal_eval(outputfile.read()) |
102 |
| - wamas_type = self.base_wamas_ubl.get_wamas_type(str_input) |
103 |
| - # Wamas Type |
104 |
| - self.assertEqual(wamas_type, dict_expected_output["wamas_type"]) |
| 4 | +from ..lib.wamas.tests.test_dict2wamas import * # noqa: F401,F403 |
| 5 | +from ..lib.wamas.tests.test_ubl2wamas import * # noqa: F401,F403 |
| 6 | +from ..lib.wamas.tests.test_utils import * # noqa: F401,F403 |
| 7 | +from ..lib.wamas.tests.test_wamas2dict import * # noqa: F401,F403 |
| 8 | +from ..lib.wamas.tests.test_wamas2ubl import * # noqa: F401,F403 |
| 9 | +from ..lib.wamas.tests.test_wamas2wamas import * # noqa: F401,F403 |
0 commit comments