X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/copy_structured?a=blobdiff_plain;f=tests%2Futils.py;h=e0b4e5f2f7c144bffe5120040e3b85a36c91258e;hb=c01144241aec26aa6b8fc8c2a6e9bb90136b96c9;hp=3b259b2e3aaa7c202f8b581b6b9167d1e04f1128;hpb=21df71ef1fde304b158da5989692c01f463515b5;p=plomtask diff --git a/tests/utils.py b/tests/utils.py index 3b259b2..e0b4e5f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -345,6 +345,27 @@ class TestCaseWithServer(TestCaseWithDB): 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', @@ -357,6 +378,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': [], @@ -364,12 +386,11 @@ class TestCaseWithServer(TestCaseWithDB): '_versioned': { 'title': {0: title}, 'description': {0: description}, - 'effort': {0: effort} - }, - 'conditions': [c['id'] for c in conditions] if conditions else [], - 'disables': [c['id'] for c in disables] if disables else [], - 'enables': [c['id'] for c in enables] if enables else [], - 'blockers': [c['id'] for c in 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: