diff --git a/base_wamas_ubl/lib/test_wamas2dict b/base_wamas_ubl/lib/test_wamas2dict new file mode 100755 index 00000000000..0a2e164ce2d --- /dev/null +++ b/base_wamas_ubl/lib/test_wamas2dict @@ -0,0 +1,2 @@ +#!/usr/bin/sh +/usr/bin/env python3 -m wamas.tests.test_wamas2dict diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml b/base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE2.xml similarity index 100% rename from base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml rename to base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE2.xml diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas b/base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas similarity index 100% rename from base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas rename to base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml b/base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml similarity index 100% rename from base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml rename to base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas b/base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas similarity index 100% rename from base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas rename to base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP-DESPATCH_ADVICE.xml b/base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP-DESPATCH_ADVICE.xml similarity index 100% rename from base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP-DESPATCH_ADVICE.xml rename to base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP-DESPATCH_ADVICE.xml diff --git a/base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas b/base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas similarity index 100% rename from base_wamas_ubl/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas rename to base_wamas_ubl/lib/wamas/tests/samples/UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas diff --git a/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml b/base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml similarity index 100% rename from base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml rename to base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml diff --git a/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas b/base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas similarity index 100% rename from base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas rename to base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas diff --git a/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ-DESPATCH_ADVICE.xml b/base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ-DESPATCH_ADVICE.xml similarity index 100% rename from base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ-DESPATCH_ADVICE.xml rename to base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ-DESPATCH_ADVICE.xml diff --git a/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ.wamas b/base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ.wamas similarity index 100% rename from base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ.wamas rename to base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ.wamas diff --git a/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ-DESPATCH_ADVICE.xml b/base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ-DESPATCH_ADVICE.xml similarity index 100% rename from base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ-DESPATCH_ADVICE.xml rename to base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ-DESPATCH_ADVICE.xml diff --git a/base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ.wamas b/base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ.wamas similarity index 100% rename from base_wamas_ubl/tests/samples/WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ.wamas rename to base_wamas_ubl/lib/wamas/tests/samples/WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ.wamas diff --git a/base_wamas_ubl/lib/wamas/tests/test_ubl2wamas.py b/base_wamas_ubl/lib/wamas/tests/test_ubl2wamas.py index 925a2f3ebff..d541578aa1a 100644 --- a/base_wamas_ubl/lib/wamas/tests/test_ubl2wamas.py +++ b/base_wamas_ubl/lib/wamas/tests/test_ubl2wamas.py @@ -1,7 +1,10 @@ import unittest from datetime import date, datetime +from freezegun import freeze_time +from ..utils import file_open, file_path from ..utils import set_value_to_string +from ..ubl2wamas import ubl2wamas class TestUbl2wamas(unittest.TestCase): @@ -102,6 +105,37 @@ def test_helpers(self): ) self.assertEqual(output_val, expected_output_val) + @freeze_time("2023-05-01") + def _convert_ubl2wamas( + self, input_filename, expected_output_filename, telegram_type + ): + path = file_path("tests/samples/") + with file_open(path + input_filename) as inputfile, file_open( + path + expected_output_filename + ) as outputfile: + str_input = inputfile.read() + output = ubl2wamas(str_input, telegram_type) + expected_output = outputfile.read().strip("\n") + self.assertEqual(output, expected_output) + + def test_convert_ubl2wamas_picking(self): + input_file = "UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE2.xml" + expected_output = "UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas" + msg_type = "Picking" + self._convert_ubl2wamas(input_file, expected_output, msg_type) + + def test_convert_ubl2wamas_reception(self): + input_file = "UBL2WAMAS-SAMPLE_WEAK_WEAP-DESPATCH_ADVICE.xml" + expected_output = "UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas" + msg_type = "Reception" + self._convert_ubl2wamas(input_file, expected_output, msg_type) + + def test_convert_ubl2wamas_return(self): + input_file = "UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml" + expected_output = "UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas" + msg_type = "Return" + self._convert_ubl2wamas(input_file, expected_output, msg_type) + if __name__ == "__main__": unittest.main() diff --git a/base_wamas_ubl/lib/wamas/tests/test_wamas2dict.py b/base_wamas_ubl/lib/wamas/tests/test_wamas2dict.py new file mode 100644 index 00000000000..966b4a871dd --- /dev/null +++ b/base_wamas_ubl/lib/wamas/tests/test_wamas2dict.py @@ -0,0 +1,37 @@ +# Copyright 2023 Jacques-Etienne Baudoux (BCIM) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import unittest +from pprint import pformat + +from ..utils import file_open, file_path +from ..wamas2ubl import wamas2dict + + +class TestWamas2dict(unittest.TestCase): + + maxDiff = None + + def _test(self, filename): + with file_open( + file_path("tests/samples/%s.wamas" % filename) + ) as infile, file_open( + file_path("tests/samples/%s.dict" % filename) + ) as outfile: + str_input = infile.read() + expected_output = outfile.read() + output_prettified = pformat(wamas2dict(str_input)) + self.assertEqual(output_prettified, expected_output) + + def test_normal(self): + self._test("line_WATEPQ_-_normal") + + def test_non_ascii(self): + self._test("line_WATEPQ_-_non_ascii") + + def test_length_off(self): + self._test("line_WATEKQ_-_length_off_by_one_01") + + +if __name__ == "__main__": + unittest.main() diff --git a/base_wamas_ubl/lib/wamas/tests/test_wamas2ubl.py b/base_wamas_ubl/lib/wamas/tests/test_wamas2ubl.py index 966b4a871dd..32295ffeb53 100644 --- a/base_wamas_ubl/lib/wamas/tests/test_wamas2ubl.py +++ b/base_wamas_ubl/lib/wamas/tests/test_wamas2ubl.py @@ -2,35 +2,41 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import unittest -from pprint import pformat +from freezegun import freeze_time from ..utils import file_open, file_path -from ..wamas2ubl import wamas2dict +from ..wamas2ubl import wamas2ubl -class TestWamas2dict(unittest.TestCase): +class TestWamas2ubl(unittest.TestCase): maxDiff = None - def _test(self, filename): - with file_open( - file_path("tests/samples/%s.wamas" % filename) - ) as infile, file_open( - file_path("tests/samples/%s.dict" % filename) - ) as outfile: - str_input = infile.read() - expected_output = outfile.read() - output_prettified = pformat(wamas2dict(str_input)) - self.assertEqual(output_prettified, expected_output) - - def test_normal(self): - self._test("line_WATEPQ_-_normal") - - def test_non_ascii(self): - self._test("line_WATEPQ_-_non_ascii") - - def test_length_off(self): - self._test("line_WATEKQ_-_length_off_by_one_01") + @freeze_time("2023-05-01") + def _convert_wamas2ubl(self, input_filename, expected_output_filename): + path = file_path("tests/samples/") + with file_open(path + input_filename) as inputfile, file_open( + path + expected_output_filename + ) as outputfile: + str_input = inputfile.read() + output = "\n".join(wamas2ubl(str_input)) + expected_output = outputfile.read() + self.assertEqual(output, expected_output) + + def test_convert_wamas2ubl_picking(self): + input_file = "WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas" + lst_expected_output = "WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml" + self._convert_wamas2ubl(input_file, lst_expected_output) + + def test_convert_wamas2ubl_reception(self): + input_file = "WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ.wamas" + lst_expected_output = "WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ-DESPATCH_ADVICE.xml" + self._convert_wamas2ubl(input_file, lst_expected_output) + + def test_convert_wamas2ubl_return(self): + input_file = "WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ.wamas" + lst_expected_output = "WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ-DESPATCH_ADVICE.xml" + self._convert_wamas2ubl(input_file, lst_expected_output) if __name__ == "__main__": diff --git a/base_wamas_ubl/tests/test_base_wamas_ubl.py b/base_wamas_ubl/tests/test_base_wamas_ubl.py index 92f5ba6d3f6..2cffb5ec598 100644 --- a/base_wamas_ubl/tests/test_base_wamas_ubl.py +++ b/base_wamas_ubl/tests/test_base_wamas_ubl.py @@ -2,8 +2,8 @@ # Copyright 2023 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from ast import literal_eval from base64 import b64decode, b64encode - from freezegun import freeze_time from odoo.tests.common import TransactionCase @@ -153,3 +153,17 @@ def test_wamas_ubl_wiz_simulate(self): "base_wamas_ubl/tests/samples/SIMULATEWAMAS-SAMPLE_OUTPUT-EXCEPTION.txt", "fail", ) + + @freeze_time("2023-12-21 04:12:51") + def test_get_wamas_type(self): + input_filename = "CHECKWAMAS-SAMPLE_INPUT.wamas" + expected_output_filename = "CHECKWAMAS-SAMPLE_OUTPUT.dict" + path = "base_wamas_ubl/tests/samples/" + with file_open(path + input_filename) as inputfile, file_open( + path + expected_output_filename + ) as outputfile: + str_input = inputfile.read() + dict_expected_output = literal_eval(outputfile.read()) + wamas_type = self.base_wamas_ubl.get_wamas_type(str_input) + # Wamas Type + self.assertEqual(wamas_type, dict_expected_output["wamas_type"]) diff --git a/base_wamas_ubl/tests/test_wamas_lib.py b/base_wamas_ubl/tests/test_wamas_lib.py index 57ee5e41233..b099be2b96c 100644 --- a/base_wamas_ubl/tests/test_wamas_lib.py +++ b/base_wamas_ubl/tests/test_wamas_lib.py @@ -1,104 +1,9 @@ # Copyright 2023 Jacques-Etienne Baudoux (BCIM) -# Copyright 2023 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from ast import literal_eval - -from freezegun import freeze_time - -from odoo.tests.common import TransactionCase -from odoo.tools import file_open - -# FIXME: all those simple convertion tests should move to lib/wamas/tests and -# there should be a test that runs the lib tests - - -class TestWamasLib(TransactionCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.base_wamas_ubl = cls.env["base.wamas.ubl"] - - @freeze_time("2023-05-01") - def _convert_wamas2ubl(self, input_filename, expected_output_filename): - path = "base_wamas_ubl/tests/samples/" - with file_open(path + input_filename) as inputfile, file_open( - path + expected_output_filename - ) as outputfile: - str_input = inputfile.read() - output = "\n".join(self.base_wamas_ubl.wamas2ubl(str_input)) - expected_output = outputfile.read() - self.assertEqual(output, expected_output) - - def test_convert_wamas2ubl_picking(self): - input_file = "WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ.wamas" - lst_expected_output = "WAMAS2UBL-SAMPLE_AUSKQ_WATEKQ_WATEPQ-DESPATCH_ADVICE.xml" - self._convert_wamas2ubl(input_file, lst_expected_output) - - def test_convert_wamas2ubl_reception(self): - input_file = "WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ.wamas" - lst_expected_output = "WAMAS2UBL-SAMPLE_WEAKQ_WEAPQ-DESPATCH_ADVICE.xml" - self._convert_wamas2ubl(input_file, lst_expected_output) - - def test_convert_wamas2ubl_return(self): - input_file = "WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ.wamas" - lst_expected_output = "WAMAS2UBL-SAMPLE_KRETKQ_KRETPQ-DESPATCH_ADVICE.xml" - self._convert_wamas2ubl(input_file, lst_expected_output) - - @freeze_time("2023-05-01") - def _convert_ubl2wamas( - self, input_filename, expected_output_filename, telegram_type - ): - path = "base_wamas_ubl/tests/samples/" - with file_open(path + input_filename) as inputfile, file_open( - path + expected_output_filename - ) as outputfile: - str_input = inputfile.read() - output = self.base_wamas_ubl.ubl2wamas(str_input, telegram_type) - expected_output = outputfile.read().strip("\n") - self.assertEqual(output, expected_output) - - def test_convert_ubl2wamas_picking(self): - input_file = "UBL2WAMAS-SAMPLE_AUSK_AUSP-DESPATCH_ADVICE.xml" - expected_output = "UBL2WAMAS-SAMPLE_AUSK_AUSP.wamas" - msg_type = "Picking" - self._convert_ubl2wamas(input_file, expected_output, msg_type) - - def test_convert_ubl2wamas_reception(self): - input_file = "UBL2WAMAS-SAMPLE_WEAK_WEAP-DESPATCH_ADVICE.xml" - expected_output = "UBL2WAMAS-SAMPLE_WEAK_WEAP.wamas" - msg_type = "Reception" - self._convert_ubl2wamas(input_file, expected_output, msg_type) - - def test_convert_ubl2wamas_return(self): - input_file = "UBL2WAMAS-SAMPLE_KRETK_KRETP-DESPATCH_ADVICE.xml" - expected_output = "UBL2WAMAS-SAMPLE_KRETK_KRETP.wamas" - msg_type = "Return" - self._convert_ubl2wamas(input_file, expected_output, msg_type) - - @freeze_time("2023-12-21 04:12:51") - def test_export_dict2wamas(self): - input_filename = "DICT2WAMAS-SAMPLE_INPUT.dict" - expected_output_filename = "DICT2WAMAS-SAMPLE_OUTPUT.wamas" - path = "base_wamas_ubl/tests/samples/" - with file_open(path + input_filename) as inputfile, file_open( - path + expected_output_filename - ) as outputfile: - dict_input = literal_eval(inputfile.read()) - output = self.base_wamas_ubl.dict2wamas(dict_input, "Supplier") - expected_output = outputfile.read() - self.assertEqual(output, expected_output) - - @freeze_time("2023-12-21 04:12:51") - def test_get_wamas_type(self): - input_filename = "CHECKWAMAS-SAMPLE_INPUT.wamas" - expected_output_filename = "CHECKWAMAS-SAMPLE_OUTPUT.dict" - path = "base_wamas_ubl/tests/samples/" - with file_open(path + input_filename) as inputfile, file_open( - path + expected_output_filename - ) as outputfile: - str_input = inputfile.read() - dict_expected_output = literal_eval(outputfile.read()) - wamas_type = self.base_wamas_ubl.get_wamas_type(str_input) - # Wamas Type - self.assertEqual(wamas_type, dict_expected_output["wamas_type"]) +from ..lib.wamas.tests.test_dict2wamas import * # noqa: F401,F403 +from ..lib.wamas.tests.test_ubl2wamas import * # noqa: F401,F403 +from ..lib.wamas.tests.test_utils import * # noqa: F401,F403 +from ..lib.wamas.tests.test_wamas2dict import * # noqa: F401,F403 +from ..lib.wamas.tests.test_wamas2ubl import * # noqa: F401,F403 +from ..lib.wamas.tests.test_wamas2wamas import * # noqa: F401,F403