Skip to content

Commit d35a89c

Browse files
committed
Merge PR #1068 into 16.0
Signed-off-by jbaudoux
2 parents acb5645 + 8e6280a commit d35a89c

22 files changed

+146
-127
lines changed

base_wamas_ubl/lib/test_wamas2dict

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/sh
2+
/usr/bin/env python3 -m wamas.tests.test_wamas2dict

base_wamas_ubl/lib/wamas/dict2wamas.py

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from ast import literal_eval
77
from pprint import pformat
88

9+
from freezegun import freeze_time
10+
911
from . import const, utils
1012

1113
_logger = logging.getLogger("json2wamas")
@@ -60,6 +62,7 @@ def dict2wamas(dict_input, msg_type):
6062
return wamas
6163

6264

65+
@freeze_time("2024-02-11 22:14:22")
6366
def main():
6467
parser = argparse.ArgumentParser(
6568
description="Converts JSON document into message.",

base_wamas_ubl/lib/wamas/tests/test_dict2wamas.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import ast
22
import unittest
33

4+
from freezegun import freeze_time
5+
46
from ..dict2wamas import dict2wamas
57
from ..utils import file_open, file_path
68

79

810
class TestDict2wamas(unittest.TestCase):
11+
12+
maxDiff = None
13+
914
def _test(self, msg_type, filename):
1015
with file_open(
1116
file_path("tests/samples/dict2wamas_input%s.dict" % filename)
@@ -17,9 +22,11 @@ def _test(self, msg_type, filename):
1722
expected_output = outfile.read()
1823
self.assertEqual(output, expected_output)
1924

25+
@freeze_time("2024-02-11 22:14:22")
2026
def test_LST(self):
2127
self._test("Supplier", "")
2228

29+
@freeze_time("2024-02-11 22:15:32")
2330
def test_KSTAUS(self):
2431
self._test("CustomerDeliveryPreferences", "_2")
2532

base_wamas_ubl/lib/wamas/tests/test_ubl2wamas.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import unittest
22
from datetime import date, datetime
33

4-
from ..utils import set_value_to_string
4+
from freezegun import freeze_time
5+
6+
from ..ubl2wamas import ubl2wamas
7+
from ..utils import file_open, file_path, set_value_to_string
58

69

710
class TestUbl2wamas(unittest.TestCase):
11+
12+
maxDiff = None
13+
814
def test_helpers(self):
915
dict_data = {
1016
"str": [
@@ -99,6 +105,37 @@ def test_helpers(self):
99105
)
100106
self.assertEqual(output_val, expected_output_val)
101107

108+
@freeze_time("2023-05-01")
109+
def _convert_ubl2wamas(
110+
self, input_filename, expected_output_filename, telegram_type
111+
):
112+
path = file_path("tests/samples/")
113+
with file_open(path + input_filename) as inputfile, file_open(
114+
path + expected_output_filename
115+
) as outputfile:
116+
str_input = inputfile.read()
117+
output = ubl2wamas(str_input, telegram_type)
118+
expected_output = outputfile.read().strip("\n")
119+
self.assertEqual(output, expected_output)
120+
121+
def test_convert_ubl2wamas_picking(self):
122+
input_file = "UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE2.xml"
123+
expected_output = "UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas"
124+
msg_type = "Picking"
125+
self._convert_ubl2wamas(input_file, expected_output, msg_type)
126+
127+
def test_convert_ubl2wamas_reception(self):
128+
input_file = "UBL2WAMAS-SAMPLE_WEAK_WEAP-DESPATCH_ADVICE.xml"
129+
expected_output = "UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas"
130+
msg_type = "Reception"
131+
self._convert_ubl2wamas(input_file, expected_output, msg_type)
132+
133+
def test_convert_ubl2wamas_return(self):
134+
input_file = "UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml"
135+
expected_output = "UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas"
136+
msg_type = "Return"
137+
self._convert_ubl2wamas(input_file, expected_output, msg_type)
138+
102139

103140
if __name__ == "__main__":
104141
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
import unittest
5+
from pprint import pformat
6+
7+
from ..utils import file_open, file_path
8+
from ..wamas2ubl import wamas2dict
9+
10+
11+
class TestWamas2dict(unittest.TestCase):
12+
13+
maxDiff = None
14+
15+
def _test(self, filename):
16+
with file_open(
17+
file_path("tests/samples/%s.wamas" % filename)
18+
) as infile, file_open(
19+
file_path("tests/samples/%s.dict" % filename)
20+
) as outfile:
21+
str_input = infile.read()
22+
expected_output = outfile.read()
23+
output_prettified = pformat(wamas2dict(str_input))
24+
self.assertEqual(output_prettified, expected_output)
25+
26+
def test_normal(self):
27+
self._test("line_WATEPQ_-_normal")
28+
29+
def test_non_ascii(self):
30+
self._test("line_WATEPQ_-_non_ascii")
31+
32+
def test_length_off(self):
33+
self._test("line_WATEKQ_-_length_off_by_one_01")
34+
35+
36+
if __name__ == "__main__":
37+
unittest.main()

base_wamas_ubl/lib/wamas/tests/test_wamas2ubl.py

+34-24
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,42 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
33

44
import unittest
5-
from pprint import pformat
65

7-
from ..utils import file_open, file_path
8-
from ..wamas2ubl import wamas2dict
9-
10-
11-
class TestWamas2dict(unittest.TestCase):
12-
def _test(self, filename):
13-
with file_open(
14-
file_path("tests/samples/%s.wamas" % filename)
15-
) as infile, file_open(
16-
file_path("tests/samples/%s.dict" % filename)
17-
) as outfile:
18-
str_input = infile.read()
19-
expected_output = outfile.read()
20-
output_prettified = pformat(wamas2dict(str_input))
21-
self.assertEqual(output_prettified, expected_output)
6+
from freezegun import freeze_time
227

23-
def test_normal(self):
24-
self._test("line_WATEPQ_-_normal")
25-
26-
def test_non_ascii(self):
27-
self._test("line_WATEPQ_-_non_ascii")
28-
29-
def test_length_off(self):
30-
self._test("line_WATEKQ_-_length_off_by_one_01")
8+
from ..utils import file_open, file_path
9+
from ..wamas2ubl import wamas2ubl
10+
11+
12+
class TestWamas2ubl(unittest.TestCase):
13+
14+
maxDiff = None
15+
16+
@freeze_time("2023-05-01")
17+
def _convert_wamas2ubl(self, input_filename, expected_output_filename):
18+
path = file_path("tests/samples/")
19+
with file_open(path + input_filename) as inputfile, file_open(
20+
path + expected_output_filename
21+
) as outputfile:
22+
str_input = inputfile.read()
23+
output = "\n".join(wamas2ubl(str_input))
24+
expected_output = outputfile.read()
25+
self.assertEqual(output, expected_output)
26+
27+
def test_convert_wamas2ubl_picking(self):
28+
input_file = "WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas"
29+
lst_expected_output = "WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml"
30+
self._convert_wamas2ubl(input_file, lst_expected_output)
31+
32+
def test_convert_wamas2ubl_reception(self):
33+
input_file = "WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ.wamas"
34+
lst_expected_output = "WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ-DESPATCH_ADVICE.xml"
35+
self._convert_wamas2ubl(input_file, lst_expected_output)
36+
37+
def test_convert_wamas2ubl_return(self):
38+
input_file = "WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ.wamas"
39+
lst_expected_output = "WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ-DESPATCH_ADVICE.xml"
40+
self._convert_wamas2ubl(input_file, lst_expected_output)
3141

3242

3343
if __name__ == "__main__":

base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88

99
class TestWamas2wamas(unittest.TestCase):
10+
11+
maxDiff = None
12+
1013
def _test(self, filename):
1114
with file_open(
1215
file_path("tests/samples/wamas2wamas_input_%s.wamas" % filename)

base_wamas_ubl/lib/wamas/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def fw2dict(line, grammar, telegram_type):
408408
dp = fdef["dp"]
409409
val = float(b[:-dp] + "." + b[-dp:])
410410
else:
411-
val = escape(b.rstrip())
411+
val = str(escape(b.rstrip()))
412412
res[fname] = val
413413
_logger.debug(pformat(res))
414414
return res

base_wamas_ubl/tests/test_base_wamas_ubl.py

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright 2023 Camptocamp SA
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

5+
from ast import literal_eval
56
from base64 import b64decode, b64encode
67

78
from freezegun import freeze_time
@@ -153,3 +154,17 @@ def test_wamas_ubl_wiz_simulate(self):
153154
"base_wamas_ubl/tests/samples/SIMULATEWAMAS-SAMPLE_OUTPUT-EXCEPTION.txt",
154155
"fail",
155156
)
157+
158+
@freeze_time("2023-12-21 04:12:51")
159+
def test_get_wamas_type(self):
160+
input_filename = "CHECKWAMAS-SAMPLE_INPUT.wamas"
161+
expected_output_filename = "CHECKWAMAS-SAMPLE_OUTPUT.dict"
162+
path = "base_wamas_ubl/tests/samples/"
163+
with file_open(path + input_filename) as inputfile, file_open(
164+
path + expected_output_filename
165+
) as outputfile:
166+
str_input = inputfile.read()
167+
dict_expected_output = literal_eval(outputfile.read())
168+
wamas_type = self.base_wamas_ubl.get_wamas_type(str_input)
169+
# Wamas Type
170+
self.assertEqual(wamas_type, dict_expected_output["wamas_type"])
+6-101
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,9 @@
11
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
2-
# Copyright 2023 Camptocamp SA
32
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
43

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

Comments
 (0)