Esempio n. 1
0
 def wrapper(*args, **kwargs):
     try:
         coverage = get_coverage(request)
         token = get_token(request)
     except exceptions.HeaderAbsent, e:
         return marshal({'error': {'message': utils.parse_error(e)}},
                        fields.error_fields), 400
Esempio n. 2
0
    def post(self, client):
        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('POST property: %s', json)

        try:
            validate(json, property_input_format)
        except ValidationError, e:
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400
Esempio n. 3
0
 def post(self, client):
     json = request.get_json(silent=True)
     logging.getLogger(__name__).debug('Post severity: %s', json)
     try:
         validate(json, severity_input_format)
     except ValidationError, e:
         logging.debug(str(e))
         # TODO: generate good error messages
         return marshal({'error': {'message': utils.parse_error(e)}},
                        error_fields), 400
Esempio n. 4
0
 def wrapper(*args, **kwargs):
     try:
         token = get_token(request)
         client_code = get_client_code(request)
         client_token_is_allowed(self.clients_tokens, client_code, token)
     except (exceptions.HeaderAbsent, exceptions.Unauthorized) as e:
         return marshal(
             {'error': {'message': utils.parse_error(e)}},
             fields.error_fields
         ), 401
     return func(*args, **kwargs)
def test_time_slots_is_required_in_pattern():
    try:
        validate(
            {
                "start_date": "2015-02-01T16:52:00Z",
                "end_date": "2015-02-06T16:52:00Z",
                "weekly_pattern": "1111100"
            }, pattern_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'time_slots' is a required property", True)
Esempio n. 6
0
 def post(self, client, navitia):
     self.navitia = navitia
     json = request.get_json(silent=True)
     logging.getLogger(__name__).debug('POST disruption: %s', json)
     try:
         validate(json, disruptions_input_format)
     except ValidationError, e:
         logging.debug(str(e))
         # TODO: generate good error messages
         return marshal({'error': {'message': utils.parse_error(e)}},
                        error_fields), 400
Esempio n. 7
0
 def wrapper(*args, **kwargs):
     try:
         coverage = get_coverage(request)
         token = get_token(request)
     except exceptions.HeaderAbsent as e:
         return marshal(
             {'error': {'message': utils.parse_error(e)}},
             fields.error_fields
         ), 400
     nav = Navitia(current_app.config['NAVITIA_URL'], coverage, token)
     return func(*args, navitia=nav, **kwargs)
def test_cause_is_required_in_disruption():
    try:
        validate(
            {
                "reference": "foo",
                "contributor": "contrib1",
                "note": "hello"
            }, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'cause' is a required property", True)
Esempio n. 9
0
def test_channel_types_name_is_required_in_channel():
    try:
        validate(
            {
                "name": "sms",
                "max_size": 500,
                "content_type": "text/type",
                "types": []
            }, channel_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "[] is too short", True)
Esempio n. 10
0
    def put(self, client, id):
        channel = models.Channel.get(id, client.id)
        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('PUT channel: %s', json)

        try:
            validate(json, channel_input_format)
        except ValidationError, e:
            logging.debug(str(e))
            # TODO: generate good error messages
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400
Esempio n. 11
0
    def put(self, client, id):
        channel = models.Channel.get(id, client.id)
        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('PUT channel: %s', json)

        try:
            validate(json, channel_input_format)
        except ValidationError, e:
            logging.debug(str(e))
            # TODO: generate good error messages
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400
Esempio n. 12
0
    def put(self, client, contributor, navitia, disruption_id, id):
        self.navitia = navitia
        json = request.get_json()
        logging.getLogger(__name__).debug('PUT impact: %s', json)

        try:
            validate(json, impact_input_format)
        except ValidationError, e:
            logging.debug(str(e))
            #TODO: generate good error messages
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400
Esempio n. 13
0
 def post(self, client, navitia):
     self.navitia = navitia
     json = request.get_json(silent=True)
     logging.getLogger(__name__).debug('POST disruption: %s', json)
     try:
         validate(json, disruptions_input_format)
     except ValidationError, e:
         logging.debug(str(e))
         # TODO: generate good error messages
         return marshal({'error': {
             'message': utils.parse_error(e)
         }}, error_fields), 400
Esempio n. 14
0
def test_name_required_in_channel_types():
    try:
        validate(
            {
                "name": "sms",
                "max_size": 500,
                "content_type": "text/type",
                "types": []
            }, channel_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "types should not be empty", True)
Esempio n. 15
0
class Property(flask_restful.Resource):
    def __init__(self):
        self.parsers = {'get': reqparse.RequestParser()}
        self.parsers['get'].add_argument('key').add_argument('type')

    @validate_client()
    @validate_id()
    def get(self, client, id=None):
        args = self.parsers['get'].parse_args()
        key = args['key']
        type = args['type']

        if id:
            property = models.Property.get(client.id, id)

            if property is None:
                return marshal(
                    {'error': {
                        'message': 'Property {} not found'.format(id)
                    }}, error_fields), 404

            return marshal({'property': property}, one_property_fields)
        else:
            response = {
                'properties': models.Property.all(client.id, key, type)
            }
            return marshal(response, properties_fields)

    @validate_client(True)
    def post(self, client):
        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('POST property: %s', json)

        try:
            validate(json, property_input_format)
        except ValidationError, e:
            return marshal({'error': {
                'message': utils.parse_error(e)
            }}, error_fields), 400

        property = models.Property()
        mapper.fill_from_json(property, json, mapper.property_mapping)
        property.client = client
        db.session.add(property)

        try:
            db.session.commit()
            db.session.refresh(property)
        except IntegrityError, e:
            return marshal({'error': {
                'message': utils.parse_error(e)
            }}, error_fields), 409
Esempio n. 16
0
    def put(self, client, id):

        severity = models.Severity.get(id, client.id)
        json = request.get_json()
        logging.getLogger(__name__).debug('PUT severity: %s', json)

        try:
            validate(json, severity_input_format)
        except ValidationError, e:
            logging.debug(str(e))
            #TODO: generate good error messages
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400
Esempio n. 17
0
 def wrapper(*args, **kwargs):
     try:
         contributor_code = get_contributor_code(request)
     except exceptions.HeaderAbsent as e:
         return marshal({'error': {'message': utils.parse_error(e)}},
                        fields.error_fields), 400
     contributor = models.Contributor.get_by_code(contributor_code)
     if not contributor:
         return marshal(
             {'error': {'message': 'X-Contributors {} Not Found'.format(contributor_code)}},
             fields.error_fields
         ), 404
     return func(*args, contributor=contributor, **kwargs)
Esempio n. 18
0
 def wrapper(*args, **kwargs):
     try:
         contributor_code = get_contributor_code(request)
     except exceptions.HeaderAbsent as e:
         return marshal({'error': {'message': utils.parse_error(e)}},
                        fields.error_fields), 400
     contributor = models.Contributor.get_by_code(contributor_code)
     if not contributor:
         return marshal(
             {'error': {'message': 'X-Contributors {} Not Found'.format(contributor_code)}},
             fields.error_fields
         ), 404
     return func(*args, contributor=contributor, **kwargs)
Esempio n. 19
0
def test_reference_is_required_in_disruption():
    try:
        validate(
            {
                "note": "hello",
                "contributor": "contrib1",
                "cause": {
                    "id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"
                }
            }, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'reference' is a required property", True)
def test_channel_is_required_in_message():
    try:
        validate(
            {
                "severity": {
                    "id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"
                },
                "messages": [{
                    "text": "message 1"
                }]
            }, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'channel' is a required property", True)
Esempio n. 21
0
def test_cause_is_required_in_disruption():
    try:
        validate(
            {
                "reference": "foo",
                "contributor": "contrib1",
                "publication_period": {
                    "begin": "2014-06-24T10:35:00Z",
                    "end": None
                }
            }, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'cause' is a required property", True)
Esempio n. 22
0
def test_severity_is_required_in_impcat():
    try:
        validate(
            {
                "application_periods": [{
                    "begin": "2014-04-29T16:52:00Z",
                    "end": "2014-05-22T02:15:00Z"
                }, {
                    "begin": "2014-04-29T16:52:00Z",
                    "end": "2014-05-22T02:15:00Z"
                }]
            }, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'severity' is a required property", True)
Esempio n. 23
0
def test_reference_is_required_in_disruption():
    try:
        validate(
            {
                "publication_period": {
                    "begin": "2014-06-24T10:35:00Z",
                    "end": None
                },
                "cause": {
                    "id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"
                }
            }, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'reference' is a required property", True)
Esempio n. 24
0
 def wrapper(*args, **kwargs):
     try:
         client_code = get_client_code(request)
     except exceptions.HeaderAbsent as e:
         return marshal({'error': {'message': utils.parse_error(e)}},
                        fields.error_fields), 400
     if self.create_client:
         client = models.Client.get_or_create(client_code)
     else:
         client = models.Client.get_by_code(client_code)
     if not client:
         return marshal(
             {'error': {'message': 'X-Customer-Id {} Not Found'.format(client_code)}},
             fields.error_fields
         ), 404
     return func(*args, client=client, **kwargs)
Esempio n. 25
0
    def put(self, client, id):
        property = models.Property.get(client.id, id)

        if property is None:
            return marshal({
                'error': {'message': 'Property {} not found'.format(id)}
            }, error_fields), 404

        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('PUT property: %s', json)

        try:
            validate(json, property_input_format)
        except ValidationError, e:
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400
Esempio n. 26
0
 def wrapper(*args, **kwargs):
     try:
         client_code = get_client_code(request)
     except exceptions.HeaderAbsent as e:
         return marshal({'error': {'message': utils.parse_error(e)}},
                        fields.error_fields), 400
     if self.create_client:
         client = models.Client.get_or_create(client_code)
     else:
         client = models.Client.get_by_code(client_code)
     if not client:
         return marshal(
             {'error': {'message': 'X-Customer-Id {} Not Found'.format(client_code)}},
             fields.error_fields
         ), 404
     return func(*args, client=client, **kwargs)
Esempio n. 27
0
    def post(self, client, contributor, navitia, disruption_id):
        self.navitia = navitia
        if not id_format.match(disruption_id):
            return marshal({'error': {'message': "id invalid"}},
                           error_fields), 400

        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('POST impcat: %s', json)

        try:
            validate(json, impact_input_format)
        except ValidationError, e:
            logging.debug(str(e))
            # TODO: generate good error messages
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400
Esempio n. 28
0
    def post(self, client, contributor, navitia, disruption_id):
        self.navitia = navitia
        if not id_format.match(disruption_id):
            return marshal({'error': {'message': "id invalid"}},
                           error_fields), 400

        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('POST impact: %s', json)

        try:
            validate(json, impact_input_format)
        except ValidationError, e:
            logging.debug(str(e))
            # TODO: generate good error messages
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400
def test_begin_date_is_required_in_disruption():
    try:
        validate(
            {
                "reference": "foo",
                "contributor": "contrib1",
                "publication_period": {
                    "end": None
                },
                "cause": {
                    "id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"
                }
            }, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'begin' is a required property", True)
Esempio n. 30
0
    def put(self, client, id):
        property = models.Property.get(client.id, id)

        if property is None:
            return marshal({
                'error': {'message': 'Property {} not found'.format(id)}
            }, error_fields), 404

        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('PUT property: %s', json)

        try:
            validate(json, property_input_format)
        except ValidationError, e:
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400
Esempio n. 31
0
class Category(flask_restful.Resource):
    @validate_client()
    @validate_id()
    def get(self, client, id=None):
        if id:
            response = {'category': models.Category.get(id, client.id)}
            return marshal(response, one_category_fields)
        else:
            response = {
                'categories': models.Category.all(client.id),
                'meta': {}
            }
            return marshal(response, categories_fields)

    @validate_client(True)
    def post(self, client):
        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('Post category: %s', json)
        try:
            validate(json, category_input_format)
        except ValidationError, e:
            logging.debug(str(e))
            # TODO: generate good error messages
            return marshal({'error': {
                'message': utils.parse_error(e)
            }}, error_fields), 400

        # if an archived category exists with same name use the same instead of creating a new one.
        archived_category = models.Category.get_archived_by_name(
            json['name'], client.id)
        if archived_category:
            category = archived_category
            category.is_visible = True
        else:
            category = models.Category()
            mapper.fill_from_json(category, json, mapper.category_mapping)
            category.client = client
            db.session.add(category)

        try:
            db.session.commit()
            db.session.refresh(category)
        except IntegrityError, e:
            logging.debug(str(e))
            return marshal({'error': {
                'message': utils.parse_error(e)
            }}, error_fields), 400
Esempio n. 32
0
def test_type_object_is_required_in_impcat():
    try:
        validate(
            {
                "severity": {
                    "id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"
                },
                "objects": [{
                    "id": "network:JDR:2",
                    "type": "network"
                }, {
                    "id": "network:JDR:1"
                }]
            }, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'type' is a required property", True)
def test_begin_date_is_required_in_impcat():
    try:
        validate(
            {
                "severity": {
                    "id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"
                },
                "application_periods": [{
                    "end": "2014-05-22T02:15:00Z"
                }, {
                    "begin": "2014-04-29T16:52:00Z",
                    "end": "2014-05-22T02:15:00Z"
                }]
            }, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'begin' is a required property", True)
Esempio n. 34
0
def test_not_pt_object_in_impcat():
    try:
        validate(
            {
                "severity": {
                    "id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"
                },
                "objects": [{
                    "id": "route_point:JDR:2",
                    "type": "route_point"
                }]
            }, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e),
            "'route_point' is not one of {}".format(pt_object_type_values),
            True)
Esempio n. 35
0
class Cause(flask_restful.Resource):
    def __init__(self):
        self.parsers = {}
        self.parsers["get"] = reqparse.RequestParser()
        parser_get = self.parsers["get"]
        parser_get.add_argument("category", type=utils.get_uuid)

    @validate_client()
    @validate_id()
    def get(self, client, id=None):
        args = self.parsers['get'].parse_args()
        category_id = args['category']
        if id:
            response = {'cause': models.Cause.get(id, client.id, category_id)}
            return marshal(response, one_cause_fields)
        else:
            response = {
                'causes': models.Cause.all(client.id, category_id),
                'meta': {}
            }
            return marshal(response, causes_fields)

    @validate_client(True)
    def post(self, client):
        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('Post cause: %s', json)
        try:
            validate(json, cause_input_format)
        except ValidationError, e:
            logging.debug(str(e))
            # TODO: generate good error messages
            return marshal({'error': {
                'message': utils.parse_error(e)
            }}, error_fields), 400

        cause = models.Cause()
        mapper.fill_from_json(cause, json, mapper.cause_mapping)
        cause.client = client
        try:
            db_helper.manage_wordings(cause, json["wordings"])
        except exceptions.InvalidJson, e:
            return marshal({'error': {
                'message': utils.parse_error(e)
            }}, error_fields), 400
Esempio n. 36
0
class Tag(flask_restful.Resource):
    @validate_client()
    @validate_id()
    def get(self, client, id=None):
        if id:
            response = {'tag': models.Tag.get(id, client.id)}
            return marshal(response, one_tag_fields)
        else:
            response = {'tags': models.Tag.all(client.id), 'meta': {}}
            return marshal(response, tags_fields)

    @validate_client(True)
    def post(self, client):
        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('Post tag: %s', json)
        try:
            validate(json, tag_input_format)
        except ValidationError, e:
            logging.debug(str(e))
            # TODO: generate good error messages
            return marshal({'error': {
                'message': utils.parse_error(e)
            }}, error_fields), 400

        # if an archived tag exists with same name use the same instead of creating a new one.
        archived_tag = models.Tag.get_archived_by_name(json['name'], client.id)
        if archived_tag:
            tag = archived_tag
            tag.client = client
            tag.is_visible = True
        else:
            tag = models.Tag()
            mapper.fill_from_json(tag, json, mapper.tag_mapping)
            tag.client = client
            db.session.add(tag)

        try:
            db.session.commit()
        except IntegrityError, e:
            logging.debug(str(e))
            return marshal({'error': {
                'message': utils.parse_error(e)
            }}, error_fields), 400
Esempio n. 37
0
def test_unique_localization_in_disruption():
    try:
        validate(
            {
                "reference":
                "foo",
                "contributor":
                "contrib1",
                "publication_period": {
                    "begin": "2014-06-24T10:35:00Z",
                    "end": None
                },
                "localization": [{
                    "id": "stop_area:JDR:SA:CHVIN",
                    "type": "stop_area"
                }, {
                    "id": "stop_area:JDR:SA:CHVIN",
                    "type": "stop_area"
                }],
                "cause": {
                    "id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"
                },
                "impacts": [{
                    "severity": {
                        "id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"
                    },
                    "objects": [{
                        "id": "network:JDR:1",
                        "type": "network"
                    }],
                    "application_periods": [{
                        "begin": "2014-04-29T16:52:00Z",
                        "end": "2014-06-22T02:15:00Z"
                    }]
                }]
            }, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(
            parse_error(e),
            "[{'type': 'stop_area', 'id': 'stop_area:JDR:SA:CHVIN'}, {'type': 'stop_area', 'id': 'stop_area:JDR:SA:CHVIN'}] has non-unique elements",
            True)
def test_id_is_required_in_localization():
    try:
        validate(
            {
                "reference": "foo",
                "contributor": "contrib1",
                "publication_period": {
                    "begin": "2014-06-24T10:35:00Z",
                    "end": None
                },
                "localization": [{
                    "type": "stop_area"
                }],
                "cause": {
                    "id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"
                }
            }, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'id' is a required property", True)
Esempio n. 39
0
def test_text_is_required_in_message():
    try:
        validate(
            {
                "severity": {
                    "id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"
                },
                "messages": [{
                    "channel": {
                        "id": "4ffab230-3d48-4eea-aa2c-22f8680230b6"
                    }
                }],
                "objects": [{
                    "id": "network:JDR:1",
                    "type": "network"
                }]
            }, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'text' is a required property", True)
Esempio n. 40
0
def test_unique_pt_object_in_impact():
    try:
        validate(
            {
                "severity": {
                    "id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"
                },
                "objects": [{
                    "id": "network:JDR:2",
                    "type": "network"
                }, {
                    "id": "network:JDR:2",
                    "type": "network"
                }]
            }, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(
            parse_error(e),
            "[{'type': 'network', 'id': 'network:JDR:2'}, {'type': 'network', 'id': 'network:JDR:2'}] has non-unique elements",
            True)
Esempio n. 41
0
def test_not_pt_object_in_impact():
    try:
        validate(
            {
                "severity": {
                    "id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"
                },
                "objects": [{
                    "id": "route_point:JDR:2",
                    "type": "route_point"
                }],
                "application_periods": [{
                    "begin": "2014-04-29T16:52:00Z",
                    "end": "2014-06-22T02:15:00Z"
                }]
            }, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e),
            "'route_point' is not one of {}".format(pt_object_type_values),
            True)
Esempio n. 42
0
def test_type_object_is_required_in_impact():
    try:
        validate(
            {
                "severity": {
                    "id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"
                },
                "objects": [{
                    "id": "network:JDR:2",
                    "type": "network"
                }, {
                    "id": "network:JDR:1"
                }],
                "application_periods": [{
                    "begin": "2014-04-29T16:52:00Z",
                    "end": "2014-06-22T02:15:00Z"
                }]
            }, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'type' is a required property", True)
def test_unique_application_periods_in_impact():
    try:
        validate(
            {
                "severity": {
                    "id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"
                },
                "application_periods": [{
                    "begin": "2014-04-29T16:52:00Z",
                    "end": "2014-05-22T02:15:00Z"
                }, {
                    "begin": "2014-04-29T16:52:00Z",
                    "end": "2014-05-22T02:15:00Z"
                }]
            }, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(
            parse_error(e),
            "[{'begin': '2014-04-29T16:52:00Z', 'end': '2014-05-22T02:15:00Z'}, {'begin': '2014-04-29T16:52:00Z', 'end': '2014-05-22T02:15:00Z'}] has non-unique elements",
            True)
Esempio n. 44
0
def test_name_is_required_in_tag():
    try:
        validate({}, tag_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'name' is a required property", True)
Esempio n. 45
0
def test_unique_tag_in_disruption():
    try:
        validate({"reference": "foo", "contributor": "contrib1", "publication_period": {"begin": "2014-06-24T10:35:00Z", "end": None}, "tags":[{"id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"}, {"id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"}], "cause":{"id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"},"impacts": [{"severity": {"id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"},"objects": [{"id": "network:JDR:1","type": "network"}],"application_periods": [{"begin": "2014-04-29T16:52:00Z","end": "2014-06-22T02:15:00Z"}]}]}, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "[{'id': '7ffab230-3d48-4eea-aa2c-22f8680230b6'}, {'id': '7ffab230-3d48-4eea-aa2c-22f8680230b6'}] has non-unique elements", True)
Esempio n. 46
0
def test_id_tag_format_is_not_valid_in_disruption():
    try:
        validate({"reference": "foo", "contributor": "contrib1", "publication_period": {"begin": "2014-06-24T10:35:00Z", "end": None}, "tags":[{"id": "7ffab230-3d48-4eea-aa2c-22f8680230"}, {"id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"}], "cause":{"id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"},"impacts": [{"severity": {"id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"},"objects": [{"id": "network:JDR:1","type": "network"}],"application_periods": [{"begin": "2014-04-29T16:52:00Z","end": "2014-06-22T02:15:00Z"}]}]}, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'7ffab230-3d48-4eea-aa2c-22f8680230' does not match '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'", True)
Esempio n. 47
0
def test_contributor_is_required_in_disruption():
    try:
        validate({"reference": "foo", "note": "hello", "cause":{"id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"},"impacts": [{"severity": {"id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"},"objects": [{"id": "network:JDR:1","type": "network"}],"application_periods": [{"begin": "2014-04-29T16:52:00Z","end": "2014-06-22T02:15:00Z"}]}]}, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'contributor' is a required property", True)
Esempio n. 48
0
def test_error_with_message():
    error = Obj()
    error.message = 'message'
    eq_(parse_error(error), 'message', True)
Esempio n. 49
0
def test_unique_message_in_impact():
    try:
        validate({"severity": {"id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"}, "messages": [{"text": "message 1","channel": {"id": "4ffab230-3d48-4eea-aa2c-22f8680230b6"}}, {"text": "message 1","channel": {"id": "4ffab230-3d48-4eea-aa2c-22f8680230b6"}}],"objects": [{"id": "network:JDR:1", "type": "network"}]}, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "[{'text': 'message 1', 'channel': {'id': '4ffab230-3d48-4eea-aa2c-22f8680230b6'}}, {'text': 'message 1', 'channel': {'id': '4ffab230-3d48-4eea-aa2c-22f8680230b6'}}] has non-unique elements", True)
Esempio n. 50
0
def test_channel_types_is_required_in_channel():
    try:
        validate({"name": "sms", "max_size": 500, "content_type": "text/type"}, channel_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'types' is a required property", True)
Esempio n. 51
0
def test_wording_is_required_in_severity():
    try:
        validate({}, severity_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'wordings' is a required property", True)
Esempio n. 52
0
def test_name_required_in_channel_types():
    try:
        validate({"name": "sms", "max_size": 500, "content_type": "text/type", "types": []}, channel_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "[] is too short", True)
Esempio n. 53
0
def test_reference_is_required_in_disruption():
    try:
        validate({"note": "hello", "contributor": "contrib1", "cause":{"id": "7ffab230-3d48-4eea-aa2c-22f8680230b6"}}, disruptions_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'reference' is a required property", True)
Esempio n. 54
0
def test_error_without_message():
    error = Obj()
    error.message = 'aa \n bbb \n c'
    eq_(parse_error(error.message), 'aa   bbb   c', True)
Esempio n. 55
0
def test_obects_is_required_in_impact():
    try:
        validate({"severity": {"id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"}, "messages": [{"text": "message 1", "channel": {"id": "4ffab230-3d48-4eea-aa2c-22f8680230b6"}}, {"text": "message 1", "channel": {"id": "4ffab230-3d48-4eea-aa2c-22f8680230b6"}}]}, impact_input_format)
        assert True
    except ValidationError, e:
        eq_(parse_error(e), "'objects' is a required property", True)
Esempio n. 56
0
def test_wording_is_empty_key_in__wordings_severity():
    try:
        validate({'wordings': [{'key': '', 'value': 'aa'}]}, severity_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'' is too short", True)
Esempio n. 57
0
def test_unique_pt_object_in_impact():
    try:
        validate({"severity": {"id": "7ffab232-3d48-4eea-aa2c-22f8680230b6"}, "objects": [{"id": "network:JDR:2","type": "network"}, {"id": "network:JDR:2","type": "network"}]}, impact_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "[{'type': 'network', 'id': 'network:JDR:2'}, {'type': 'network', 'id': 'network:JDR:2'}] has non-unique elements", True)
Esempio n. 58
0
def test_wording_is_key_not_in__wordings_severity():
    try:
        validate({'wordings': [{'key': 'aa'}]}, severity_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'value' is a required property", True)
Esempio n. 59
0
        json = request.get_json(silent=True)
        logging.getLogger(__name__).debug('PUT severity: %s', json)

        try:
            validate(json, severity_input_format)
        except ValidationError, e:
            logging.debug(str(e))
            # TODO: generate good error messages
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400

        mapper.fill_from_json(severity, json, mapper.severity_mapping)
        try:
            db_helper.manage_wordings(severity, json["wordings"])
        except exceptions.InvalidJson, e:
            return marshal({'error': {'message': utils.parse_error(e)}},
                           error_fields), 400
        db.session.commit()
        db.session.refresh(severity)
        return marshal({'severity': severity}, one_severity_fields), 200

    @validate_client()
    @validate_id(True)
    def delete(self, client, id):

        severity = models.Severity.get(id, client.id)
        severity.is_visible = False
        db.session.commit()
        return None, 204

Esempio n. 60
0
def test_time_slots_is_required_in_pattern():
    try:
        validate({"start_date":"2015-02-01T16:52:00Z","end_date":"2015-02-06T16:52:00Z","weekly_pattern":"1111100"}, pattern_input_format)
        assert False
    except ValidationError, e:
        eq_(parse_error(e), "'time_slots' is a required property", True)