Exemple #1
0
def test_live_stop_ambiguous(api_data):
    # Last Sunday of October, at 00:50 UTC (01:50 local time)
    api_data.update({
        "request_time": "2019-10-27T00:50:45Z",
    })
    # Don't need 2nd service
    del api_data["departures"]["all"][1]
    # Next service is at 01:30 local time - in the repeated 1st hour
    api_data["departures"]["all"][0].update({
        "date": "2019-10-27",
        "expected_departure_date": "2019-10-27",
        "aimed_departure_time": "01:30",
        "expected_departure_time": "01:30",
        "best_departure_estimate": "01:30",
    })
    live_data = tapi.LiveData(api_data)
    assert live_data.datetime.isoformat() == "2019-10-27T00:50:45+00:00"

    service = live_data.services[0][0]
    assert service.is_live
    assert service.expected == "2019-10-27T01:30:00+00:00"
    assert service.seconds == 2355
    assert tapi.LiveData(api_data).to_json() == {
        "atcoCode":
        "490000015G",
        "live":
        True,
        "smsCode":
        "53272",
        "isoDate":
        "2019-10-27T00:50:45+00:00",
        "localTime":
        "01:50",
        "services": [{
            "line":
            "Barking Dagenham Sunday Market Shuttle",
            "name":
            "Barking Dagenham Sunday Market Shuttle",
            "dest":
            "Dagenham Sunday Market",
            "opName":
            "AT Coaches",
            "opCode":
            "ATC",
            "expected": [{
                "live": True,
                "secs": 2355,
                "expDate": "2019-10-27T01:30:00+00:00"
            }]
        }]
    }
Exemple #2
0
def test_live_json_threshold(api_data):
    # Setting max minutes to 10 should filter out the last departure
    assert tapi.LiveData(api_data).to_json(max_minutes=10) == {
        "atcoCode":
        "490000015G",
        "live":
        True,
        "smsCode":
        "53272",
        "isoDate":
        "2019-06-02T08:25:45+00:00",
        "localTime":
        "09:25",
        "services": [{
            "line":
            "Barking Dagenham Sunday Market Shuttle",
            "name":
            "Barking Dagenham Sunday Market Shuttle",
            "dest":
            "Dagenham Sunday Market",
            "opName":
            "AT Coaches",
            "opCode":
            "ATC",
            "expected": [{
                "live": True,
                "secs": 255,
                "expDate": "2019-06-02T09:30:00+01:00"
            }]
        }]
    }
Exemple #3
0
def test_live_json_out_of_date(api_data):
    api_data.update({"request_time": "2019-06-02T09:25:45Z"})
    assert tapi.LiveData(api_data).to_json() == {
        "atcoCode": "490000015G",
        "live": True,
        "smsCode": "53272",
        "isoDate": "2019-06-02T09:25:45+00:00",
        "localTime": "10:25",
        "services": []
    }
Exemple #4
0
def test_live_json(api_data):
    expected = {
        "atcoCode":
        "490000015G",
        "live":
        True,
        "smsCode":
        "53272",
        "isoDate":
        "2019-06-02T08:25:45+00:00",
        "localTime":
        "09:25",
        "services": [{
            "line":
            "Barking Dagenham Sunday Market Shuttle",
            "name":
            "Barking Dagenham Sunday Market Shuttle",
            "dest":
            "Dagenham Sunday Market",
            "opName":
            "AT Coaches",
            "opCode":
            "ATC",
            "expected": [{
                "live": True,
                "secs": 255,
                "expDate": "2019-06-02T09:30:00+01:00"
            }, {
                "live": False,
                "secs": 2055,
                "expDate": "2019-06-02T10:00:00+01:00"
            }]
        }]
    }
    assert tapi.LiveData(api_data).to_json() == expected
    # Switch around services - should still output same order
    api_data["departures"]["all"] = api_data["departures"]["all"][::-1]
    assert tapi.LiveData(api_data).to_json() == expected
Exemple #5
0
def test_live_stop_live(api_data):
    live_data = tapi.LiveData(api_data)
    assert live_data.datetime.isoformat() == "2019-06-02T08:25:45+00:00"
    assert live_data.atco_code == "490000015G"
    assert live_data.naptan_code == "53272"

    assert len(live_data.services) == 1
    assert len(live_data.services[0]) == 2

    first = live_data.services[0][0]
    assert first.line == "Barking Dagenham Sunday Market Shuttle"
    assert first.name == "Barking Dagenham Sunday Market Shuttle"
    assert first.destination == "Dagenham Sunday Market"
    assert first.operator == "ATC"
    assert first.operator_name == "AT Coaches"
    assert first.is_live
    assert first.expected == "2019-06-02T09:30:00+01:00"
    assert first.seconds == 255