示例#1
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
示例#2
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/')

    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):
        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
示例#3
0
def next_passage_for_no_departures_response_test(mock_no_departure_response):
    """
    test the whole next_passage_for_route_point
    mock the http call to return a response without any departures, we should get no departure
    """
    sytral = Sytral(id='tata', service_url='http://bob.com/')

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

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

    with mock.patch('requests.get', mock_requests.get):
        passages = sytral.next_passage_for_route_point(route_point)

        assert passages == []
示例#4
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
示例#5
0
def next_passage_for_empty_response_test(mock_empty_response):
    """
    test the whole next_passage_for_route_point
    mock the http call to return a empty response, we should get None
    """
    sytral = Sytral(id='tata',
                    service_url='http://bob.com/',
                    instance=MockInstance())

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

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

    with mock.patch('requests.get', mock_requests.get):
        passages = sytral.next_passage_for_route_point(route_point)

        assert passages is None
示例#6
0
def next_passage_for_missing_line_response_test(mock_missing_line_response):
    """
    test the whole next_passage_for_route_point
    mock the http call to return a response without wanted line  we should get no departure
    """
    sytral = Sytral(id='tata',
                    service_url='http://bob.com/',
                    service_args={
                        'a': 'bobette',
                        'b': '12'
                    })

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

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

    with mock.patch('requests.get', mock_requests.get):
        passages = sytral.next_passage_for_route_point(route_point)

        assert passages == []
示例#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
示例#8
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'
                    })

    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):
        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