def api_rules(): if flask.request.method == 'GET': res = [rule_repr(rule, short=True) for rule in rules.get_all()] return flask.jsonify(rules=res) elif flask.request.method == 'DELETE': rules.delete_all() return _generate_empty_response(204) else: body = flask.request.get_json(force=True) if body.get('uuid') and not uuidutils.is_uuid_like(body['uuid']): raise utils.Error(_('Invalid UUID value'), code=400) if body.get('scope') and len(body.get('scope')) > 255: raise utils.Error(_( "Invalid scope: the length of the scope should be within " "255 characters"), code=400) rule = rules.create(conditions_json=body.get('conditions', []), actions_json=body.get('actions', []), uuid=body.get('uuid'), description=body.get('description'), scope=body.get('scope')) response_code = (200 if _get_version() < (1, 6) else 201) return flask.make_response(flask.jsonify(rule_repr(rule, short=False)), response_code)
def api_rules(): utils.check_auth(flask.request) if flask.request.method == 'GET': res = [rule_repr(rule, short=True) for rule in rules.get_all()] return flask.jsonify(rules=res) elif flask.request.method == 'DELETE': rules.delete_all() return '', 204 else: body = flask.request.get_json(force=True) if body.get('uuid') and not uuidutils.is_uuid_like(body['uuid']): raise utils.Error(_('Invalid UUID value'), code=400) rule = rules.create(conditions_json=body.get('conditions', []), actions_json=body.get('actions', []), uuid=body.get('uuid'), description=body.get('description')) return flask.jsonify(rule_repr(rule, short=False))
def test_get_all(self): uuid2 = uuidutils.generate_uuid() rules.create(self.conditions_json, self.actions_json, uuid=uuid2) self.assertEqual({self.uuid, uuid2}, {r.as_dict()['uuid'] for r in rules.get_all()})
def test_get_all(self): rules.create(self.conditions_json, self.actions_json, uuid='uuid2') self.assertEqual([self.uuid, 'uuid2'], [r.as_dict()['uuid'] for r in rules.get_all()])