+ """Test POST /condition and its effect on GET /condition[s]."""
+ # test valid POST's effect on …
+ post = {'title': 'foo', 'description': 'oof', 'is_active': False}
+ self.check_post(post, '/condition', 302, '/condition?id=1')
+ # … single /condition
+ cond = self.cond_as_dict(titles=['foo'], descriptions=['oof'])
+ assert isinstance(cond['_versioned'], dict)
+ expected_single = self.GET_condition_dict(cond)
+ self.check_json_get('/condition?id=1', expected_single)
+ # … full /conditions
+ expected_all = self.GET_conditions_dict([cond])
+ self.check_json_get('/conditions', expected_all)
+ # test (no) effect of invalid POST to existing Condition on /condition
+ self.check_post({}, '/condition?id=1', 400)
+ self.check_json_get('/condition?id=1', expected_single)
+ # test effect of POST changing title and activeness
+ post = {'title': 'bar', 'description': 'oof', 'is_active': True}
+ self.check_post(post, '/condition?id=1', 302)
+ cond['_versioned']['title'][1] = 'bar'
+ cond['is_active'] = True
+ self.check_json_get('/condition?id=1', expected_single)
+ # test deletion POST's effect on …
+ self.check_post({'delete': ''}, '/condition?id=1', 302, '/conditions')
+ cond = self.cond_as_dict()
+ assert isinstance(expected_single['_library'], dict)
+ expected_single['_library']['Condition'] = self.as_refs([cond])
+ self.check_json_get('/condition?id=1', expected_single)
+ # … full /conditions
+ expected_all['conditions'] = []
+ expected_all['_library'] = {}
+ self.check_json_get('/conditions', expected_all)
+
+ def test_do_GET_condition(self) -> None:
+ """More GET /condition testing, especially for Process relations."""
+ # check expected default status codes
+ self.check_get_defaults('/condition')
+ # make Condition and two Processes that among them establish all
+ # possible ConditionsRelations to it, …
+ cond_post = {'title': 'foo', 'description': 'oof', 'is_active': False}
+ self.check_post(cond_post, '/condition', 302, '/condition?id=1')
+ proc1_post = {'title': 'A', 'description': '', 'effort': 1.0,
+ 'conditions': [1], 'disables': [1]}
+ proc2_post = {'title': 'B', 'description': '', 'effort': 1.0,
+ 'enables': [1], 'blockers': [1]}
+ self.post_process(1, proc1_post)
+ self.post_process(2, proc2_post)
+ # … then check /condition displays all these properly.
+ cond = self.cond_as_dict(titles=['foo'], descriptions=['oof'])
+ assert isinstance(cond['id'], int)
+ proc1 = self.proc_as_dict(conditions=[cond['id']],
+ disables=[cond['id']])
+ proc2 = self.proc_as_dict(2, 'B',
+ blockers=[cond['id']],
+ enables=[cond['id']])
+ expected = self.GET_condition_dict(cond)
+ assert isinstance(expected['_library'], dict)
+ expected['enabled_processes'] = self.as_id_list([proc1])
+ expected['disabled_processes'] = self.as_id_list([proc2])
+ expected['enabling_processes'] = self.as_id_list([proc2])
+ expected['disabling_processes'] = self.as_id_list([proc1])
+ expected['_library']['Process'] = self.as_refs([proc1, proc2])
+ self.check_json_get('/condition?id=1', expected)