Пример #1
0
def test_live_data_arguments_ungrouped(with_app, mock_request):
    current_app.config["TRANSPORT_API_ACTIVE"] = True
    tapi.get_live_data(ATCO_CODE, group=False, limit=8)

    parameters = {"group": "no", "nextbuses": "yes", "limit": 8}
    assert mock_request.calls == [((tapi.URL_FCC.format(code=ATCO_CODE), ), {
        "params": parameters
    })]
Пример #2
0
def test_live_json_value_error(with_app, mock_response, mock_request):
    def _raise_error(*args, **kwargs):
        raise ValueError

    mock_response.json = _raise_error

    with pytest.raises(ValueError, match="Data is expected to be"):
        current_app.config["TRANSPORT_API_ACTIVE"] = True
        tapi.get_live_data(ATCO_CODE)
Пример #3
0
def test_live_data_error(with_app, mock_response, mock_request):
    def _error_response(*args, **kwargs):
        return {"error": "This is a mock error."}

    mock_response.json = _error_response

    message = "Error with data: This is a mock error."
    with pytest.raises(ValueError, match=message):
        current_app.config["TRANSPORT_API_ACTIVE"] = True
        tapi.get_live_data(ATCO_CODE)
Пример #4
0
def test_live_data_arguments_api_key(with_app, mock_request):
    api_id, api_key = "some_api_id", "some_api_key"
    current_app.config.update({
        "TRANSPORT_API_ACTIVE": True,
        "TRANSPORT_API_ID": api_id,
        "TRANSPORT_API_KEY": api_key
    })
    tapi.get_live_data(ATCO_CODE)

    parameters = {
        "group": "yes",
        "nextbuses": "yes",
        "limit": 6,
        "app_id": api_id,
        "app_key": api_key
    }
    assert mock_request.calls == [((tapi.URL_API.format(code=ATCO_CODE), ), {
        "params": parameters
    })]
Пример #5
0
def test_live_data_data(with_app, mock_request):
    current_app.config["TRANSPORT_API_ACTIVE"] = True
    new_data = tapi.get_live_data(ATCO_CODE)

    assert new_data == {"name": "A bus stop"}
Пример #6
0
def test_live_data_inactive(with_app, mock_request):
    current_app.config["TRANSPORT_API_ACTIVE"] = False
    with pytest.raises(ValueError, match="TRANSPORT_API_ACTIVE not set"):
        tapi.get_live_data("", group=False)