- """Test POST /condition and its effect on the database."""
- form_data = {'title': 'foo', 'description': 'foo', 'is_active': False}
- self.check_post(form_data, '/condition', 302, '/condition?id=1')
- self.assertEqual(1, len(Condition.all(self.db_conn)))
- form_data['delete'] = ''
- self.check_post(form_data, '/condition?id=', 404)
- self.check_post(form_data, '/condition?id=2', 404)
- self.check_post(form_data, '/condition?id=1', 302, '/conditions')
- self.assertEqual(0, len(Condition.all(self.db_conn)))
+ """Test POST /condition and its effect on GET /condition[s]."""
+ # check empty POST fails
+ self.check_post({}, '/condition', 400)
+ # 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'])
+ expected_single: dict[str, object]
+ expected_single = {'is_new': False,
+ 'enabled_processes': [],
+ 'disabled_processes': [],
+ 'enabling_processes': [],
+ 'disabling_processes': [],
+ 'condition': cond}
+ self.check_json_get('/condition?id=1', expected_single)
+ # … full /conditions
+ expected_all: dict[str, object]
+ expected_all = {'conditions': [cond],
+ 'sort_by': 'title', 'pattern': ''}
+ self.check_json_get('/conditions', expected_all)
+ # test 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)
+ assert isinstance(expected_single['condition'], dict)
+ expected_single['condition']['_versioned']['title'][1] = 'bar'
+ expected_single['condition']['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()
+ expected_single['condition'] = cond
+ self.check_json_get('/condition?id=1', expected_single)
+ # … full /conditions
+ expected_all['conditions'] = []
+ self.check_json_get('/conditions', expected_all)