def crud_subscription(case_name, action): if action == 'edit': form = forms.EditSubscriptionForm(request.form) if form.validate(): success = case_subscription.edit_subscription( case_name, form.ancestry.data, form.events.data) if success: return json.dumps(case_subscription.subscriptions_as_json()) else: return json.dumps( {"status": "Error occurred while editing subscription"}) else: return json.dumps({ "status": "Error: Case name {0} was not found".format(case_name) }) elif action == 'add': form = forms.AddSubscriptionForm(request.form) if form.validate(): case_subscription.add_subscription(case_name, form.ancestry.data, form.events.data) return json.dumps(case_subscription.subscriptions_as_json()) elif action == 'delete': form = forms.DeleteSubscriptionForm(request.form) if form.validate(): case_subscription.remove_subscription_node(case_name, form.ancestry.data) return json.dumps(case_subscription.subscriptions_as_json())
def delete_subscription(case_name): if request.get_json(): data = request.get_json() if 'ancestry' in data: case_subscription.remove_subscription_node( case_name, convert_ancestry(data['ancestry'])) running_context.CaseSubscription.update(case_name) running_context.db.session.commit() return json.dumps(case_subscription.subscriptions_as_json()) else: return json.dumps({"status": "Error: malformed JSON"}) else: return json.dumps({"status": "Error: no JSON in request"})
def test_remove_subscription_node(self): cases = copy.deepcopy(self.cases1) subs.set_subscriptions(self.cases1) subs.remove_subscription_node('case1', 'uid1') cases['case1'].pop('uid1') self.assertInMemoryCasesAreCorrect(cases)
def test_remove_subscription_node_case_not_found(self): cases = copy.deepcopy(self.cases1) subs.set_subscriptions(self.cases1) subs.remove_subscription_node('invalid', 'uid1') self.assertInMemoryCasesAreCorrect(cases)
def test_remove_subscription_node_no_cases(self): subs.remove_subscription_node('invalid', 'uid1') self.assertInMemoryCasesAreCorrect({})