示例#1
0
def test_login_sets_key_id(responses, fake_url):
    responses.add(responses.GET,
                  "{}/api/".format(fake_url),
                  json={},
                  status=200)

    session = APISession(fake_url)
    session.login(secret_key_id="monty", secret_key_password="******")

    assert session.key_id == "monty"
示例#2
0
def test_login_sets_correct_user_agent(responses, fake_url):
    responses.add(responses.GET,
                  "{}/api/".format(fake_url),
                  json={},
                  status=200)

    session = APISession(fake_url)
    session.login(secret_key_id="monty", secret_key_password="******")

    assert session.headers["User-Agent"] == f"belvo-python ({__version__})"
示例#3
0
def test_login_returns_false_when_bad_response(wrong_http_code, responses,
                                               fake_url):
    responses.add(responses.GET,
                  "{}/api/".format(fake_url),
                  json={},
                  status=wrong_http_code)

    session = APISession(fake_url)
    result = session.login(secret_key_id="monty", secret_key_password="******")

    assert not result
示例#4
0
def test_patch_doesnt_raise_exception_on_error_by_default(responses, fake_url):
    responses.add(
        responses.PATCH,
        "{}/fake-resource/".format(fake_url),
        json=[{
            "code": "unsupported",
            "message": "Wait, that's illegal!"
        }],
        status=400,
    )
    session = APISession(fake_url)

    result = session.patch("/fake-resource/", {})

    assert result == [{
        "code": "unsupported",
        "message": "Wait, that's illegal!"
    }]
    assert responses.calls[0].request.headers[
        "Content-Type"] == "application/json"
示例#5
0
def test_post_raises_exception_on_error_if_raises_exception_is_true(
        responses, fake_url):
    responses.add(
        responses.POST,
        "{}/fake-resource/".format(fake_url),
        json=[{
            "code": "unsupported",
            "message": "Wait, that's illegal!"
        }],
        status=400,
    )
    session = APISession(fake_url)

    with pytest.raises(RequestError) as exc:
        session.post("/fake-resource/", {}, raise_exception=True)

    assert exc.value.status_code == 400
    assert exc.value.detail == [{
        "code": "unsupported",
        "message": "Wait, that's illegal!"
    }]
    assert responses.calls[0].request.headers[
        "Content-Type"] == "application/json"
示例#6
0
def api_session(fake_url, authorized_response):
    session = APISession(fake_url)
    session.login(secret_key_id="monty", secret_key_password="******")
    yield session