Ejemplo n.º 1
0
def next_passage_for_route_point_with_direction_type_test(
        mock_direction_type_is_forward_response):
    """
    test the whole next_passage_for_route_point with direction_type parameter
    mock the http call to return a good response, we should get some next_passages
    """
    sytral = Sytral(id='tata', service_url='http://bob.com/')

    mock_requests = MockRequests({
        'http://bob.com/?direction_type=forward&stop_id=42':
        (mock_direction_type_is_forward_response, 200)
    })

    route_point = MockRoutePoint(line_code='05',
                                 stop_id='42',
                                 direction_type='forward')

    with mock.patch('requests.get', mock_requests.get):
        with mock.patch(
                'jormungandr.realtime_schedule.sytral.Sytral._get_direction',
                lambda Sytral, **kwargs: Direction("3341", "Piscine Chambéry"),
        ):
            passages = sytral.next_passage_for_route_point(route_point)

            assert len(passages) == 1

            assert passages[0].datetime == datetime.datetime(2016,
                                                             4,
                                                             11,
                                                             12,
                                                             37,
                                                             15,
                                                             tzinfo=pytz.UTC)
            assert passages[0].is_real_time
Ejemplo n.º 2
0
def get_direction_name_with_destination_id_tag_test():

    timeo = Timeo(
        id=u"tata-é$~#@\"*!'`§èû",
        timezone='UTC',
        service_url='http://bob.com/',
        service_args={
            'a': 'bobette',
            'b': '12'
        },
        destination_id_tag="source",
        instance=MockInstance(),
    )
    stop_point = type_pb2.PtObject()
    stop_point.embedded_type = type_pb2.STOP_POINT
    stop_point.stop_area.label = 'destination de Bob'
    stop_point.stop_area.uri = 'destination_de_Bob'

    with mock.patch(
            'jormungandr.ptref.PtRef.get_stop_point',
            lambda PtRef, line_uri, destination_id_tag, object_code:
            stop_point,
    ):
        result = timeo._get_direction("line_uri", "object_code",
                                      "default_value")
        assert result == Direction("destination_de_Bob", "destination de Bob")
Ejemplo n.º 3
0
def get_passages_stop_time_with_is_realtime_test():
    """
    test the next departures get from timeo's response

    the timezone is UTC for convenience
    """
    timeo = Timeo(id='tata',
                  timezone='UTC',
                  service_url='http://bob.com/tata',
                  service_args={
                      'a': 'bobette',
                      'b': '12'
                  })

    mock_response = mock_good_timeo_response(criteria=3)

    # we need to mock the datetime.now() because for timeo we don't have a choice but to combine
    # the current day with the timeo's response
    with mock.patch(
            'jormungandr.realtime_schedule.timeo.Timeo._get_direction',
            lambda timeo, **kwargs: Direction("StopPoint_Bob", "A direction"),
    ):
        passages = timeo._get_passages(MockResponse(200, 'http://bob.com/tata',
                                                    mock_response),
                                       current_dt=_dt("02:02"))

        assert len(passages) == 1

        assert passages[0].datetime == _dt('16:10:04')
Ejemplo n.º 4
0
def next_passage_for_route_point_multi_stop_point_id_test(
        mock_multi_stop_point_id_response):
    """
    test next_passage for route point with multi stop point ID
    """
    sytral = Sytral(id='tata',
                    service_url='http://bob.com/',
                    instance=MockInstance())

    mock_requests = MockRequests({
        'http://bob.com/?stop_id=42&stop_id=43':
        (mock_multi_stop_point_id_response, 200)
    })

    route_point = MockRoutePoint(line_code='05', stop_id=['42', '43'])

    with mock.patch('requests.get', mock_requests.get):
        with mock.patch(
                'jormungandr.realtime_schedule.sytral.Sytral._get_direction',
                lambda Sytral, **kwargs: Direction("3341", "Piscine Chambéry"),
        ):
            passages = sytral.next_passage_for_route_point(route_point)

            assert len(passages) == 4

            # Stop id 42
            assert passages[0].datetime == datetime.datetime(2016,
                                                             4,
                                                             11,
                                                             13,
                                                             37,
                                                             15,
                                                             tzinfo=pytz.UTC)
            assert not passages[0].is_real_time
            assert passages[1].datetime == datetime.datetime(2016,
                                                             4,
                                                             11,
                                                             13,
                                                             45,
                                                             35,
                                                             tzinfo=pytz.UTC)
            assert passages[1].is_real_time
            # Stop id 43
            assert passages[2].datetime == datetime.datetime(2016,
                                                             4,
                                                             11,
                                                             13,
                                                             38,
                                                             15,
                                                             tzinfo=pytz.UTC)
            assert not passages[2].is_real_time
            assert passages[3].datetime == datetime.datetime(2016,
                                                             4,
                                                             11,
                                                             13,
                                                             47,
                                                             35,
                                                             tzinfo=pytz.UTC)
            assert passages[3].is_real_time
Ejemplo n.º 5
0
def next_passage_with_theoric_time_response_test(mock_theoric_response):
    """
    test the whole next_passage_for_route_point
    mock the http call to return a response with a theoric time we should get one departure
    """
    sytral = Sytral(
        id='tata',
        service_url='http://bob.com/',
        service_args={
            'a': 'bobette',
            'b': '12'
        },
        instance=MockInstance(),
    )

    mock_requests = MockRequests(
        {'http://bob.com/?stop_id=42': (mock_theoric_response, 200)})

    route_point = MockRoutePoint(line_code='05', stop_id='42')

    with mock.patch('requests.get', mock_requests.get):
        with mock.patch(
                'jormungandr.realtime_schedule.sytral.Sytral._get_direction',
                lambda Sytral, **kwargs: Direction("3341", "Piscine Chambéry"),
        ):
            passages = sytral.next_passage_for_route_point(route_point)

            assert len(passages) == 2

            assert passages[0].datetime == datetime.datetime(2016,
                                                             4,
                                                             11,
                                                             13,
                                                             37,
                                                             15,
                                                             tzinfo=pytz.UTC)
            assert not passages[0].is_real_time
            assert passages[1].datetime == datetime.datetime(2016,
                                                             4,
                                                             11,
                                                             13,
                                                             45,
                                                             35,
                                                             tzinfo=pytz.UTC)
            assert passages[1].is_real_time
Ejemplo n.º 6
0
def next_passage_for_route_point_test():
    """
    test the whole next_passage_for_route_point
    mock the http call to return a good timeo response, we should get some next_passages
    """
    timeo = Timeo(id='tata',
                  timezone='UTC',
                  service_url='http://bob.com/tata',
                  service_args={
                      'a': 'bobette',
                      'b': '12'
                  })

    mock_requests = MockRequests({
        'http://bob.com/tata?a=bobette&b=12&StopDescription=?StopTimeType=TR&LineTimeoCode'
        '=line_toto&Way=route_tata&NextStopTimeNumber=5&StopTimeoCode=stop_tutu;':
        (
            mock_good_timeo_response(),
            200,
        )
    })

    route_point = MockRoutePoint(route_id='route_tata',
                                 line_id='line_toto',
                                 stop_id='stop_tutu')
    # we mock the http call to return the hard coded mock_response
    with mock.patch('requests.get', mock_requests.get):
        with mock.patch(
                'jormungandr.realtime_schedule.timeo.Timeo._get_direction',
                lambda timeo, **kwargs: Direction("StopPoint_Bob",
                                                  "A direction"),
        ):
            passages = timeo.next_passage_for_route_point(
                route_point, current_dt=_dt("02:02"))

            assert len(passages) == 3

            assert passages[0].datetime == _dt('15:40:04')
            assert passages[1].datetime == _dt('15:55:04')
            assert passages[2].datetime == _dt('16:10:04')
Ejemplo n.º 7
0
def next_passage_for_route_point_multiline_test(mock_multiline_response):
    """
    test the whole next_passage_for_route_point with a routepoint having multiple SAE lines
    """
    sytral = Sytral(id='tata',
                    service_url='http://bob.com/',
                    instance=MockInstance())

    mock_requests = MockRequests(
        {'http://bob.com/?stop_id=42': (mock_multiline_response, 200)})

    route_point = MockRoutePoint(line_code=['05A', '05B'], stop_id='42')

    with mock.patch('requests.get', mock_requests.get):
        with mock.patch(
                'jormungandr.realtime_schedule.sytral.Sytral._get_direction',
                lambda Sytral, **kwargs: Direction("3341", "Piscine Chambéry"),
        ):
            passages = sytral.next_passage_for_route_point(route_point)

            assert len(passages) == 2

            assert passages[0].datetime == datetime.datetime(2016,
                                                             4,
                                                             11,
                                                             12,
                                                             37,
                                                             15,
                                                             tzinfo=pytz.UTC)
            assert passages[0].is_real_time
            assert passages[1].datetime == datetime.datetime(2016,
                                                             4,
                                                             11,
                                                             12,
                                                             45,
                                                             35,
                                                             tzinfo=pytz.UTC)
            assert passages[1].is_real_time