Beispiel #1
0
def make_request_test():
    siri = Siri(id='tata',
                service_url='http://bob.com/',
                requestor_ref='Stibada',
                from_datetime_step=30)

    request = siri._make_request(dt=_timestamp("12:00"),
                                 count=2,
                                 monitoring_ref='Tri:SP:toto:LOC')

    # it should be a valid xml
    root = et.fromstring(request)
    ns = {'siri': 'http://www.siri.org.uk/siri'}

    assert root.find('.//siri:MonitoringRef', ns).text == 'Tri:SP:toto:LOC'
    assert root.find('.//siri:MinimumStopVisitsPerLine', ns).text == '2'
    assert root.find('.//siri:RequestTimestamp',
                     ns).text == '2016-02-07T12:00:00'
    assert root.find('.//siri:RequestorRef', ns).text == 'Stibada'

    request = siri._make_request(dt=_timestamp("12:00:12"),
                                 count=2,
                                 monitoring_ref='Tri:SP:toto:LOC')
    root = et.fromstring(request)
    assert root.find('.//siri:RequestTimestamp',
                     ns).text == '2016-02-07T12:00:00'

    request = siri._make_request(dt=_timestamp("12:00:33"),
                                 count=2,
                                 monitoring_ref='Tri:SP:toto:LOC')
    root = et.fromstring(request)
    assert root.find('.//siri:RequestTimestamp',
                     ns).text == '2016-02-07T12:00:30'
Beispiel #2
0
def next_passage_for_route_point_good_response_with_error_test():
    """
    mock the http call to return a good response that also contains an error, we should get some next_passages
    """
    siri = Siri(id='tata',
                service_url='http://bob.com/',
                requestor_ref='Stibada')
    route_point = MockRoutePoint(route_id='route_tata',
                                 line_id='line_toto',
                                 stop_id='stop_tutu')

    with requests_mock.Mocker() as m:
        m.post('http://bob.com/', text=mock_good_with_error_response())
        passages = siri._get_next_passage_for_route_point(
            route_point,
            from_dt=_timestamp("12:00"),
            current_dt=_timestamp("12:00"),
            count=1)
        assert m.called
        assert len(passages) == 1
        assert passages[0].datetime == datetime.datetime(2016,
                                                         3,
                                                         29,
                                                         13,
                                                         37,
                                                         tzinfo=pytz.UTC)
Beispiel #3
0
def next_passage_for_route_point_test():
    """
    test the whole next_passage_for_route_point
    mock the http call to return a good response, we should get some next_passages
    """
    siri = Siri(id='tata',
                service_url='http://bob.com/',
                requestor_ref='Stibada')
    mock_requests = MockRequests(
        {'http://bob.com/': (mock_good_response(), 200)})
    route_point = MockRoutePoint(route_id='route_tata',
                                 line_id='line_toto',
                                 stop_id='stop_tutu')

    with mock.patch('requests.post', mock_requests.post):
        passages = siri._get_next_passage_for_route_point(
            route_point,
            from_dt=_timestamp("12:00"),
            current_dt=_timestamp("12:00"),
            count=1)
        assert len(passages) == 1
        assert passages[0].datetime == datetime.datetime(2016,
                                                         3,
                                                         29,
                                                         13,
                                                         37,
                                                         tzinfo=pytz.UTC)
Beispiel #4
0
def next_passage_for_route_point_failure_test():
    """
    test the whole next_passage_for_route_point

    the siri's response is in error (status = 404), we should get 'None'
    """
    siri = Siri(id='tata', service_url='http://bob.com/', requestor_ref='Stibada')

    mock_requests = MockRequests({'http://bob.com/': (mock_good_response(), 404)})

    route_point = MockRoutePoint(route_id='route_tata', line_id='line_toto', stop_id='stop_tutu')

    with mock.patch('requests.post', mock_requests.post):
        passages = siri.next_passage_for_route_point(route_point, from_dt=_timestamp("12:00"), count=2)

        assert passages is None
Beispiel #5
0
def next_passage_for_route_point_failure_test():
    """
    test the whole next_passage_for_route_point

    the siri's response is in error (status = 404), we should get 'None'
    """
    siri = Siri(id='tata', service_url='http://bob.com/', requestor_ref='Stibada')

    route_point = MockRoutePoint(route_id='route_tata', line_id='line_toto', stop_id='stop_tutu')

    with requests_mock.Mocker() as m:
        m.post('http://bob.com/', text=mock_good_response(), status_code=404)
        passages = siri.next_passage_for_route_point(route_point, from_dt=_timestamp("12:00"), count=2)
        assert m.called

        assert passages is None
Beispiel #6
0
def next_passage_for_route_point_no_data_test():
    """
    test the whole next_passage_for_route_point

    the siri's response contains an error of type NoInfoForTopicError: there is no next departure
    """
    siri = Siri(id='tata', service_url='http://bob.com/', requestor_ref='Stibada')

    route_point = MockRoutePoint(route_id='route_tata', line_id='line_toto', stop_id='stop_tutu')

    with requests_mock.Mocker() as m:
        m.post('http://bob.com/', text=mock_no_data_response(), status_code=200)
        passages = siri.next_passage_for_route_point(route_point, from_dt=_timestamp("12:00"), count=2)
        assert m.called

        assert passages == []
Beispiel #7
0
def status_test():
    siri = Siri(id='tata', service_url='http://bob.com/', requestor_ref='Stibada')
    status = siri.status()
    assert status['id'] == 'tata'
Beispiel #8
0
def status_test():
    siri = Siri(id=u"tata-é$~#@\"*!'`§èû", service_url='http://bob.com/', requestor_ref='Stibada')
    status = siri.status()
    assert status['id'] == u'tata-é$~#@"*!\'`§èû'