From 426822b57c35f6ea4caba97eb9989c6c72e83c60 Mon Sep 17 00:00:00 2001 From: Sebastian Aranda Sanchez Date: Wed, 18 Dec 2024 17:40:44 -0300 Subject: [PATCH] Extend tests to support new components_json field. --- src/narrativelog/testutils.py | 13 ++++++++++++- tests/test_add_message.py | 2 ++ tests/test_edit_message.py | 11 +++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/narrativelog/testutils.py b/src/narrativelog/testutils.py index 4673cba..2959a41 100644 --- a/src/narrativelog/testutils.py +++ b/src/narrativelog/testutils.py @@ -63,6 +63,11 @@ TEST_PRIMARY_HARDWARE_COMPONENTS = [ f"primary_hardware_component{n}" for n in range(10) ] +TEST_COMPONENTS_JSON = { + "systems": TEST_SYSTEMS, + "subsystems": TEST_SUBSYSTEMS, + "components": TEST_COMPONENTS, +} # Type annotation aliases MessageDictT = dict[str, typing.Any] @@ -396,6 +401,8 @@ def random_message() -> MessageDictT: primary_hardware_components=random_strings( TEST_PRIMARY_HARDWARE_COMPONENTS ), + # Added 2024-12-16 + components_json=TEST_COMPONENTS_JSON, # Added 2023-10-24 category=random_str(nchar=CATEGORY_LEN), time_lost_type=random.choice(["fault", "weather"]), @@ -502,11 +509,14 @@ async def create_test_database( pruned_message = message.copy() del pruned_message["is_valid"] # Do not insert "components", - # "primary_software_components", or "primary_hardware_components" + # "primary_software_components", + # "primary_hardware_components", + # or "components_json" # because they are in a separate table. del pruned_message["components"] del pruned_message["primary_software_components"] del pruned_message["primary_hardware_components"] + del pruned_message["components_json"] # Insert the message result_message = await connection.execute( @@ -529,6 +539,7 @@ async def create_test_database( primary_hardware_components=message[ "primary_hardware_components" ], + components_json=message["components_json"], message_id=data_message.id, ) .returning(literal_column("*")) diff --git a/tests/test_add_message.py b/tests/test_add_message.py index e2b051d..498e2f2 100644 --- a/tests/test_add_message.py +++ b/tests/test_add_message.py @@ -7,6 +7,7 @@ from narrativelog.testutils import ( TEST_COMPONENTS, + TEST_COMPONENTS_JSON, TEST_CSCS, TEST_PRIMARY_HARDWARE_COMPONENTS, TEST_PRIMARY_SOFTWARE_COMPONENTS, @@ -90,6 +91,7 @@ async def test_add_message(self) -> None: add_args_full["primary_hardware_components"] = random_strings( TEST_PRIMARY_HARDWARE_COMPONENTS ) + add_args_full["components_json"] = TEST_COMPONENTS_JSON add_args_full["category"] = "test" add_args_full["time_lost_type"] = random.choice( ["fault", "weather"] diff --git a/tests/test_edit_message.py b/tests/test_edit_message.py index 1b0ea0c..7fd3fdb 100644 --- a/tests/test_edit_message.py +++ b/tests/test_edit_message.py @@ -29,6 +29,12 @@ def assert_good_edit_response( assert not old_message["is_valid"] assert new_message["date_invalidated"] is None assert old_message["date_invalidated"] is not None + + print("######", flush=True) + print("old_message:", old_message, flush=True) + print("edit_args:", edit_args, flush=True) + print("new_message:", new_message, flush=True) + print("######", flush=True) for key in old_message: if key in set( ( @@ -85,6 +91,11 @@ async def test_edit_message(self) -> None: "new primary_hardware_component 1", "new primary_hardware_component 2", ], + components_json={ + "systems": ["new system 1", "new system 2"], + "subsystems": ["new subsystem 1", "new subsystem 2"], + "components": ["new component 1", "new component 2"], + }, category="New category", time_lost_type=random.choice(["fault", "weather"]), date_begin="2024-01-01T00:00:00",