X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D?a=blobdiff_plain;ds=sidebyside;f=tests%2Futils.py;h=b115793341bac427e1df1ec71ce4412c353e4f95;hb=df81cce527b2084738523a35f49d9c53045af31d;hp=ed4101a6c32a52d1e26fadb99c35fd8c44d2178a;hpb=b56761522f6ec874fde1eb9d4d69d8093fe70227;p=plomtask diff --git a/tests/utils.py b/tests/utils.py index ed4101a..b115793 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -327,6 +327,24 @@ 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 proc_as_dict(id_: int = 1, title: str = 'A', @@ -339,6 +357,7 @@ class TestCaseWithServer(TestCaseWithDB): ) -> dict[str, object]: """Return JSON of Process to expect.""" # pylint: disable=too-many-arguments + as_id_list = TestCaseWithServer.as_id_list d = {'id': id_, 'calendarize': False, 'suppressed_steps': [], @@ -346,12 +365,11 @@ class TestCaseWithServer(TestCaseWithDB): '_versioned': { 'title': {0: title}, 'description': {0: description}, - 'effort': {0: effort} - }, - 'conditions': conditions if conditions else [], - 'disables': disables if disables else [], - 'enables': enables if enables else [], - 'blockers': blockers if blockers else []} + 'effort': {0: effort}}, + 'conditions': as_id_list(conditions) if conditions else [], + 'disables': as_id_list(disables) if disables else [], + 'enables': as_id_list(enables) if enables else [], + 'blockers': as_id_list(blockers) if blockers else []} return d def check_redirect(self, target: str) -> None: