diff --git a/integrationtests/test_ex_import_xlsx.py b/integrationtests/test_ex_import_xlsx.py index 9a9a9a0669dcf987cb9e8fa3dbc0c3559470d355..15fc437aa9db51d860fa1741191666a8f767cf15 100755 --- a/integrationtests/test_ex_import_xlsx.py +++ b/integrationtests/test_ex_import_xlsx.py @@ -47,6 +47,7 @@ from utils import ( # noqa: E402, pylint: disable=wrong-import-position set_test_key("_CAOSDB_ADV_TEST_SUITE") + def rfp(*pathcomponents): """ Return full path. @@ -166,11 +167,11 @@ def setup(clear_database): .add_property(test_prop_2, value=0) .add_property(test_prop_3, value=test_person_2)) test_conference_0 = (db.Record(description="Only for Also").add_parent(test_rt_2) - .add_property(test_prop_4, value=[test_person_1])) + .add_property(test_prop_4, value=[test_person_1])) test_conference_1 = (db.Record(name="Official Conf", description="For everyone") - .add_parent(test_rt_2) - .add_property(test_prop_4, - value=[test_person_0, test_person_1, test_person_2])) + .add_parent(test_rt_2) + .add_property(test_prop_4, + value=[test_person_0, test_person_1, test_person_2])) testdata = [test_rt_0, test_rt_1, test_rt_2, test_prop_0, test_prop_1, test_prop_2, test_prop_3, test_prop_4, @@ -183,6 +184,7 @@ def setup(clear_database): c.extend(testdata) c.insert() + def test_successful_export(): records = next(db.execute_query("FIND Record", page_length=50)) tmp_path = Path('temp_test_successful_export.xlsx') @@ -252,7 +254,6 @@ def test_export_list_refs(tmpdir): # Check: Filled XLSX filled_generated = load_workbook(tmpdir / "result.xlsx") # For the moment: just check a few samples - assert filled_generated.get_sheet_names() == ['Training', 'Training.Organisation', 'Training.Organisation.Person', diff --git a/unittests/table_json_conversion/__init__.py b/unittests/table_json_conversion/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/unittests/table_json_conversion/utils.py b/unittests/table_json_conversion/utils.py index da3d17cf175ece713cf3dc7d320f1b44445f92b7..846809d8dbc50d51dc4ca5abd281bf744014e999 100644 --- a/unittests/table_json_conversion/utils.py +++ b/unittests/table_json_conversion/utils.py @@ -21,6 +21,7 @@ """Utilities for the tests. """ +from datetime import datetime from typing import Iterable, Union from openpyxl import Workbook @@ -48,7 +49,8 @@ Raise an assertion exception if they are not equal.""" assert_equal_jsons(el1, el2, allow_none=allow_none, allow_empty=allow_empty, path=this_path) continue - assert el1 == el2, f"Values at path {this_path} are not equal:\n{el1},\n{el2}" + assert equals_with_casting(el1, el2), ( + f"Values at path {this_path} are not equal:\n{el1},\n{el2}") continue # Case 2: exists only in one collection existing = json1.get(key, json2.get(key)) @@ -66,7 +68,18 @@ Raise an assertion exception if they are not equal.""" assert_equal_jsons(el1, el2, allow_none=allow_none, allow_empty=allow_empty, path=this_path) else: - assert el1 == el2, f"Values at path {this_path} are not equal:\n{el1},\n{el2}" + assert equals_with_casting(el1, el2), ( + f"Values at path {this_path} are not equal:\n{el1},\n{el2}") + + +def equals_with_casting(value1, value2) -> bool: + """Compare two values, return True if equal, False otherwise. Try to cast to clever datatypes. + """ + try: + return datetime.fromisoformat(value1) == datetime.fromisoformat(value2) + except (ValueError, TypeError): + pass + return value1 == value2 def purge_from_json(data: Union[dict, list], remove_keys: list[str]) -> Union[dict, list]: