Skip to content

Commit

Permalink
Extend tests to support new components_json field.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-aranda committed Dec 20, 2024
1 parent 98d0663 commit 4c6d320
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/narrativelog/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"]),
Expand Down Expand Up @@ -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(
Expand All @@ -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("*"))
Expand Down
2 changes: 2 additions & 0 deletions tests/test_add_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from narrativelog.testutils import (
TEST_COMPONENTS,
TEST_COMPONENTS_JSON,
TEST_CSCS,
TEST_PRIMARY_HARDWARE_COMPONENTS,
TEST_PRIMARY_SOFTWARE_COMPONENTS,
Expand Down Expand Up @@ -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"]
Expand Down
5 changes: 5 additions & 0 deletions tests/test_edit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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",
Expand Down

0 comments on commit 4c6d320

Please sign in to comment.