Skip to content

Commit

Permalink
base_wamas_ubl: move lib tests to lib and run them all
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaudoux committed Nov 16, 2024
1 parent 8fd25db commit a4b93b3
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 124 deletions.
2 changes: 2 additions & 0 deletions base_wamas_ubl/lib/test_wamas2dict
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
34 changes: 34 additions & 0 deletions base_wamas_ubl/lib/wamas/tests/test_ubl2wamas.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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()
37 changes: 37 additions & 0 deletions base_wamas_ubl/lib/wamas/tests/test_wamas2dict.py
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()
50 changes: 28 additions & 22 deletions base_wamas_ubl/lib/wamas/tests/test_wamas2ubl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
16 changes: 15 additions & 1 deletion base_wamas_ubl/tests/test_base_wamas_ubl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"])
107 changes: 6 additions & 101 deletions base_wamas_ubl/tests/test_wamas_lib.py
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

0 comments on commit a4b93b3

Please sign in to comment.