def test_impacts_by_pt_object_uris():
    impacts = []
    one_impact = Obj()
    one_impact.id = '1'
    one_impact.objects = []
    one_pt_object = Obj()
    one_pt_object.uri = 'b'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'a'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'c'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'c'
    one_pt_object.type = 'network'
    one_impact.objects.append(one_pt_object)

    impacts.append(one_impact)
    uris = ['a', 'c']
    result = utils.group_impacts_by_pt_object(impacts, None, uris,
                                              get_pt_object)
    eq_(len(result), 2)
    eq_(result[0]['name'], 'a')
    eq_(result[1]['name'], 'c')
def test_impacts_by_pt_object_type_uri():
    impacts = []
    one_impact = Obj()
    one_impact.id = '1'
    one_impact.objects = []
    one_pt_object = Obj()
    one_pt_object.uri = 'b'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'a'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'c'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'c'
    one_pt_object.type = 'network'
    one_impact.objects.append(one_pt_object)

    impacts.append(one_impact)

    result = utils.group_impacts_by_pt_object(impacts, 'stop_area', 'a',
                                              get_pt_object)
    eq_(len(result), 1)
    eq_(result[0]['name'], 'a')
def test_impacts_by_pt_object_uris():
    impacts = []
    one_impact = Obj()
    one_impact.id = '1'
    one_impact.objects = []
    one_pt_object = Obj()
    one_pt_object.uri = 'b'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'a'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'c'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'c'
    one_pt_object.type = 'network'
    one_impact.objects.append(one_pt_object)

    impacts.append(one_impact)
    uris = ['a', 'c']
    result = utils.group_impacts_by_pt_object(impacts, None, uris, get_pt_object)
    eq_(len(result), 2)
    eq_(result[0]['name'], 'a')
    eq_(result[1]['name'], 'c')
def test_impacts_by_pt_object_type_uri():
    impacts = []
    one_impact = Obj()
    one_impact.id = '1'
    one_impact.objects = []
    one_pt_object = Obj()
    one_pt_object.uri = 'b'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'a'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'c'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    one_pt_object = Obj()
    one_pt_object.uri = 'c'
    one_pt_object.type = 'network'
    one_impact.objects.append(one_pt_object)

    impacts.append(one_impact)

    result = utils.group_impacts_by_pt_object(impacts, 'stop_area', 'a', get_pt_object)
    eq_(len(result), 1)
    eq_(result[0]['name'], 'a')
示例#5
0
    def get(self, contributor, navitia):
        self.navitia = navitia
        args = self.parsers['get'].parse_args()
        pt_object_type = args['pt_object_type']
        start_date = args['start_date']
        end_date = args['end_date']
        uris = args['uri[]']

        if not pt_object_type and not uris:
                return marshal({'error': {'message': "object type or uri object invalid"}},
                               error_fields), 400
        impacts = models.Impact.all_with_filter(start_date, end_date, pt_object_type, uris, contributor.id)
        result = utils.group_impacts_by_pt_object(impacts, pt_object_type, uris, self.navitia.get_pt_object)
        return marshal({'objects': result}, impacts_by_object_fields)
示例#6
0
    def get(self, contributor, navitia):
        self.navitia = navitia
        args = self.parsers['get'].parse_args()
        pt_object_type = args['pt_object_type']
        start_date = args['start_date']
        end_date = args['end_date']
        uris = args['uri[]']

        if not pt_object_type and not uris:
                return marshal({'error': {'message': "object type or uri object invalid"}},
                               error_fields), 400
        impacts = models.Impact.all_with_filter(start_date, end_date, pt_object_type, uris, contributor.id)
        result = utils.group_impacts_by_pt_object(impacts, pt_object_type, uris, self.navitia.get_pt_object)
        return marshal({'objects': result}, impacts_by_object_fields)
def test_impacts_pt_object_not_in_navitia():
    impacts = []
    one_impact = Obj()
    one_impact.id = '1'
    one_impact.objects = []
    one_pt_object = Obj()
    one_pt_object.uri = 'b'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    impacts.append(one_impact)
    result = utils.group_impacts_by_pt_object(impacts, 'stop_area', ['b'], None_pt_object)
    eq_(len(result), 1)
    eq_(result[0]['name'], None)
def test_impacts_pt_object_not_in_navitia():
    impacts = []
    one_impact = Obj()
    one_impact.id = '1'
    one_impact.objects = []
    one_pt_object = Obj()
    one_pt_object.uri = 'b'
    one_pt_object.type = 'stop_area'
    one_impact.objects.append(one_pt_object)

    impacts.append(one_impact)
    result = utils.group_impacts_by_pt_object(impacts, 'stop_area', ['b'],
                                              None_pt_object)
    eq_(len(result), 1)
    eq_(result[0]['name'], None)