-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base_wamas_ubl: move lib tests to lib and run them all
- Loading branch information
Showing
18 changed files
with
122 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/sh | ||
/usr/bin/env python3 -m wamas.tests.test_wamas2dict |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,9 @@ | ||
# Copyright 2023 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# 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 |