예제 #1
0
    def test_vj_deletion(self):
        """
        send a mock kirin vj cancellation and test that the vj is not taken
        """
        response = self.query_region(journey_basic_query +
                                     "&data_freshness=realtime")
        isochrone = self.query_region(isochrone_basic_query +
                                      "&data_freshness=realtime")

        # with no cancellation, we have 2 journeys, one direct and one with the vj:A:0
        eq_(get_arrivals(response), ['20120614T080222', '20120614T080435'])
        eq_(get_used_vj(response), [['vjA'], []])

        # no disruption yet
        pt_response = self.query_region(
            'vehicle_journeys/vjA?_current_datetime=20120614T1337')
        eq_(len(pt_response['disruptions']), 0)

        is_valid_graphical_isochrone(
            isochrone, self.tester,
            isochrone_basic_query + "&data_freshness=realtime")
        geojson = isochrone['isochrones'][0]['geojson']
        multi_poly = asShape(geojson)

        self.send_mock("vjA",
                       "20120614",
                       'canceled',
                       disruption_id='disruption_bob')

        # we should see the disruption
        def _check_train_cancel_disruption(dis):
            is_valid_disruption(dis, chaos_disrup=False)
            eq_(dis['disruption_id'], 'disruption_bob')
            eq_(dis['severity']['effect'], 'NO_SERVICE')
            eq_(len(dis['impacted_objects']), 1)
            ptobj = dis['impacted_objects'][0]['pt_object']
            eq_(ptobj['embedded_type'], 'trip')
            eq_(ptobj['id'], 'vjA')
            eq_(ptobj['name'], 'vjA')
            # for cancellation we do not output the impacted stops
            assert 'impacted_stops' not in dis['impacted_objects'][0]

        pt_response = self.query_region(
            'vehicle_journeys/vjA?_current_datetime=20120614T1337')
        eq_(len(pt_response['disruptions']), 1)
        _check_train_cancel_disruption(pt_response['disruptions'][0])

        # and we should be able to query for the vj's disruption
        disrup_response = self.query_region('vehicle_journeys/vjA/disruptions')
        eq_(len(disrup_response['disruptions']), 1)
        _check_train_cancel_disruption(disrup_response['disruptions'][0])

        traffic_reports_response = self.query_region(
            'traffic_reports?_current_datetime=20120614T1337')
        traffic_reports = get_not_null(traffic_reports_response,
                                       'traffic_reports')
        assert len(traffic_reports) == 1
        vjs = get_not_null(traffic_reports[0], "vehicle_journeys")
        assert len(vjs) == 1
        assert vjs[0]['id'] == 'vjA'

        new_response = self.query_region(journey_basic_query +
                                         "&data_freshness=realtime")
        eq_(get_arrivals(new_response), ['20120614T080435', '20120614T180222'])
        eq_(get_used_vj(new_response), [[], ['vjB']])

        isochrone_realtime = self.query_region(isochrone_basic_query +
                                               "&data_freshness=realtime")
        is_valid_graphical_isochrone(
            isochrone_realtime, self.tester,
            isochrone_basic_query + "&data_freshness=realtime")
        geojson_realtime = isochrone_realtime['isochrones'][0]['geojson']
        multi_poly_realtime = asShape(geojson_realtime)
        isochrone_base_schedule = self.query_region(
            isochrone_basic_query + "&data_freshness=base_schedule")
        is_valid_graphical_isochrone(
            isochrone_base_schedule, self.tester,
            isochrone_basic_query + "&data_freshness=base_schedule")
        geojson_base_schedule = isochrone_base_schedule['isochrones'][0][
            'geojson']
        multi_poly_base_schedule = asShape(geojson_base_schedule)
        assert not multi_poly.difference(multi_poly_realtime).is_empty
        assert multi_poly.equals(multi_poly_base_schedule)

        # it should not have changed anything for the theoric
        new_base = self.query_region(journey_basic_query +
                                     "&data_freshness=base_schedule")
        eq_(get_arrivals(new_base), ['20120614T080222', '20120614T080435'])
        eq_(get_used_vj(new_base), [['vjA'], []])
        # see http://jira.canaltp.fr/browse/NAVP-266,
        # _current_datetime is needed to make it working
        #eq_(len(new_base['disruptions']), 1)
        assert new_base['journeys'] == response['journeys']
예제 #2
0
    def test_vj_deletion(self):
        """
        send a mock kirin vj cancellation and test that the vj is not taken
        """
        response = self.query_region(journey_basic_query + "&data_freshness=realtime")
        isochrone = self.query_region(isochrone_basic_query + "&data_freshness=realtime")

        # with no cancellation, we have 2 journeys, one direct and one with the vj:A:0
        assert get_arrivals(response) == ['20120614T080222', '20120614T080436']
        assert get_used_vj(response) == [['vjA'], []]

        # no disruption yet
        pt_response = self.query_region('vehicle_journeys/vjA?_current_datetime=20120614T1337')
        assert len(pt_response['disruptions']) == 0

        is_valid_graphical_isochrone(isochrone, self.tester, isochrone_basic_query + "&data_freshness=realtime")
        geojson = isochrone['isochrones'][0]['geojson']
        multi_poly = asShape(geojson)

        # we have 2 departures and 1 disruption (linked to the first passage)
        departures = self.query_region("stop_points/stop_point:stopB/departures?_current_datetime=20120614T0800")
        assert len(departures['disruptions']) == 1
        assert len(departures['departures']) == 2

        self.send_mock("vjA", "20120614", 'canceled', disruption_id='disruption_bob')

        # we should see the disruption
        def _check_train_cancel_disruption(dis):
            is_valid_disruption(dis, chaos_disrup=False)
            assert dis['contributor'] == rt_topic
            assert dis['disruption_id'] == 'disruption_bob'
            assert dis['severity']['effect'] == 'NO_SERVICE'
            assert len(dis['impacted_objects']) == 1
            ptobj = dis['impacted_objects'][0]['pt_object']
            assert ptobj['embedded_type'] == 'trip'
            assert ptobj['id'] == 'vjA'
            assert ptobj['name'] == 'vjA'
            # for cancellation we do not output the impacted stops
            assert 'impacted_stops' not in dis['impacted_objects'][0]

        pt_response = self.query_region('vehicle_journeys/vjA?_current_datetime=20120614T1337')
        assert len(pt_response['disruptions']) == 1
        _check_train_cancel_disruption(pt_response['disruptions'][0])

        # and we should be able to query for the vj's disruption
        disrup_response = self.query_region('vehicle_journeys/vjA/disruptions')
        assert len(disrup_response['disruptions']) == 1
        _check_train_cancel_disruption(disrup_response['disruptions'][0])

        traffic_reports_response = self.query_region('traffic_reports?_current_datetime=20120614T0800')
        traffic_reports = get_not_null(traffic_reports_response, 'traffic_reports')
        assert len(traffic_reports) == 1
        vjs = get_not_null(traffic_reports[0], "vehicle_journeys")
        assert len(vjs) == 1
        assert vjs[0]['id'] == 'vjA'

        new_response = self.query_region(journey_basic_query + "&data_freshness=realtime")
        assert get_arrivals(new_response) == ['20120614T080436', '20120614T180222']
        assert get_used_vj(new_response) == [[], ['vjB']]

        isochrone_realtime = self.query_region(isochrone_basic_query + "&data_freshness=realtime")
        is_valid_graphical_isochrone(isochrone_realtime, self.tester, isochrone_basic_query + "&data_freshness=realtime")
        geojson_realtime = isochrone_realtime['isochrones'][0]['geojson']
        multi_poly_realtime = asShape(geojson_realtime)
        isochrone_base_schedule = self.query_region(isochrone_basic_query + "&data_freshness=base_schedule")
        is_valid_graphical_isochrone(isochrone_base_schedule, self.tester,
                                     isochrone_basic_query + "&data_freshness=base_schedule")
        geojson_base_schedule = isochrone_base_schedule['isochrones'][0]['geojson']
        multi_poly_base_schedule = asShape(geojson_base_schedule)
        assert not multi_poly.difference(multi_poly_realtime).is_empty
        assert multi_poly.equals(multi_poly_base_schedule)

        # we have one less departure and we loose the disruption in
        # realtime because we don't have the 08:01
        departures = self.query_region("stop_points/stop_point:stopB/departures?_current_datetime=20120614T0800")
        assert len(departures['disruptions']) == 0
        assert len(departures['departures']) == 1
        # We still have 2 passages in base schedule, but we have the new disruption
        departures = self.query_region("stop_points/stop_point:stopB/departures?_current_datetime=20120614T0800&data_freshness=base_schedule")
        assert len(departures['disruptions']) == 2
        assert len(departures['departures']) == 2

        # it should not have changed anything for the theoric
        new_base = self.query_region(journey_basic_query + "&data_freshness=base_schedule")
        assert get_arrivals(new_base) == ['20120614T080222', '20120614T080436']
        assert get_used_vj(new_base) == [['vjA'], []]
        # see http://jira.canaltp.fr/browse/NAVP-266,
        # _current_datetime is needed to make it working
        #assert len(new_base['disruptions']) == 1

        # remove links as the calling url is not the same
        for j in new_base['journeys']:
            j.pop('links', None)
        for j in response['journeys']:
            j.pop('links', None)
        assert new_base['journeys'] == response['journeys']