Skip to content

Commit

Permalink
fix: Raise a ValueError when a work item without ID is found
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Aug 27, 2024
1 parent 969666f commit 39b9ab2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions capella2polarion/connectors/polarion_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ def __init__(
):
if polarion_work_items is None:
polarion_work_items = []

check_work_items(polarion_work_items)
self._id_mapping = bidict.bidict(
{
work_item.uuid_capella: work_item.id
for work_item in polarion_work_items
if work_item.id is not None
},
}, # type: ignore[arg-type]
)
self._id_mapping.on_dup = bidict.OnDup(
key=bidict.DROP_OLD, val=bidict.DROP_OLD
Expand Down Expand Up @@ -91,12 +92,12 @@ def update_work_items(self, work_items: list[data_models.CapellaWorkItem]):
del self._id_mapping[uuid_capella]
del self._work_items[uuid_capella]

check_work_items(work_items)
self._id_mapping.update(
{
work_item.uuid_capella: work_item.id
for work_item in work_items
if work_item.id is not None
}
} # type: ignore[arg-type]
)
self._work_items.update(
{work_item.uuid_capella: work_item for work_item in work_items}
Expand All @@ -107,3 +108,13 @@ def remove_work_items_by_capella_uuid(self, uuids: cabc.Iterable[str]):
for uuid in uuids:
del self._work_items[uuid]
del self._id_mapping[uuid]


def check_work_items(work_items: cabc.Iterable[data_models.CapellaWorkItem]):
"""Raise a ``ValueError`` if any work item has no ID."""
if work_item_without_id := next(
(wi for wi in work_items if wi.id is None), None
):
raise ValueError(
f"Found Work Item without ID: {work_item_without_id.title!r}"
)

0 comments on commit 39b9ab2

Please sign in to comment.