def __func(): data = request.get_json() case_obj = CaseSubscription.query.filter_by(id=data['id']).first() if case_obj: original_name = case_obj.name case_name = data['name'] if 'name' in data else original_name if 'note' in data and data['note']: case_obj.note = data['note'] if 'name' in data and data['name']: case_subscription.rename_case(case_obj.name, data['name']) case_obj.name = data['name'] db.session.commit() current_app.logger.debug( 'Case name changed from {0} to {1}'.format( original_name, data['name'])) if 'subscriptions' in data: case_obj.subscriptions = json.dumps(data['subscriptions']) subscriptions = { subscription['uid']: subscription['events'] for subscription in data['subscriptions'] } for uid, events in subscriptions.items(): case_subscription.modify_subscription( case_name, uid, events) db.session.commit() return case_obj.as_json(), SUCCESS else: current_app.logger.error( 'Cannot update case {0}. Case does not exist.'.format( data['id'])) return {"error": "Case does not exist."}, OBJECT_DNE_ERROR
def test_modify_subscriptions_case_not_found(self): cases = copy.deepcopy(self.cases1) subs.set_subscriptions(self.cases1) subs.modify_subscription('invalid', 'uid1', ['e1', 'e3']) self.assertInMemoryCasesAreCorrect(cases)
def test_modify_subscriptions_new_subscriptions(self): cases = copy.deepcopy(self.cases1) subs.set_subscriptions(self.cases1) subs.modify_subscription('case1', 'uid1', ['e1', 'e3']) cases['case1']['uid1'] = ['e1', 'e3'] self.assertInMemoryCasesAreCorrect(cases)
def test_modify_subscriptions_no_cases(self): subs.modify_subscription('case1', 'uid1', ['e1', 'e3']) self.assertInMemoryCasesAreCorrect({})