X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/form?a=blobdiff_plain;f=tests%2Futils.py;h=665436873c27af704a13827715d3c795e04e1fe1;hb=f02e0fc13b49dc5b38924ba3ad8c485007a72cb2;hp=ed4101a6c32a52d1e26fadb99c35fd8c44d2178a;hpb=b56761522f6ec874fde1eb9d4d69d8093fe70227;p=plomtask diff --git a/tests/utils.py b/tests/utils.py index ed4101a..6654368 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -327,15 +327,54 @@ class TestCaseWithServer(TestCaseWithDB): self.server_thread.join() super().tearDown() + @staticmethod + def as_id_list(items: list[dict[str, object]]) -> list[int | str]: + """Return list of only 'id' fields of items.""" + id_list = [] + for item in items: + assert isinstance(item['id'], (int, str)) + id_list += [item['id']] + return id_list + + @staticmethod + def as_refs(items: list[dict[str, object]] + ) -> dict[str, dict[str, object]]: + """Return dictionary of items by their 'id' fields.""" + refs = {} + for item in items: + refs[str(item['id'])] = item + return refs + + @staticmethod + def cond_as_dict(id_: int = 1, + is_active: bool = False, + titles: None | list[str] = None, + descriptions: None | list[str] = None + ) -> dict[str, object]: + """Return JSON of Condition to expect.""" + d = {'id': id_, + 'is_active': is_active, + '_versioned': { + 'title': {}, + 'description': {}}} + titles = titles if titles else [] + descriptions = descriptions if descriptions else [] + assert isinstance(d['_versioned'], dict) + for i, title in enumerate(titles): + d['_versioned']['title'][i] = title + for i, description in enumerate(descriptions): + d['_versioned']['description'][i] = description + return d + @staticmethod def proc_as_dict(id_: int = 1, title: str = 'A', description: str = '', effort: float = 1.0, - enables: None | list[dict[str, object]] = None, - disables: None | list[dict[str, object]] = None, - conditions: None | list[dict[str, object]] = None, - blockers: None | list[dict[str, object]] = None + conditions: None | list[int] = None, + disables: None | list[int] = None, + blockers: None | list[int] = None, + enables: None | list[int] = None ) -> dict[str, object]: """Return JSON of Process to expect.""" # pylint: disable=too-many-arguments @@ -346,8 +385,7 @@ class TestCaseWithServer(TestCaseWithDB): '_versioned': { 'title': {0: title}, 'description': {0: description}, - 'effort': {0: effort} - }, + 'effort': {0: effort}}, 'conditions': conditions if conditions else [], 'disables': disables if disables else [], 'enables': enables if enables else [],