Skip to content

Commit

Permalink
restore test_wrapped_methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aviau committed Aug 15, 2024
1 parent 47dbaec commit 3ce961e
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,69 @@ def test_bad_domain() -> None:
match="Please only use the client to access the api.flare.io domain.",
):
client.post("https://bad.com/hello-post")


def test_wrapped_methods() -> None:
client = _get_test_client()
assert client.token is None
assert client.token_exp is None

# POST: This one will generate since its the first one.
with requests_mock.Mocker() as mocker:
mocker.register_uri(
"POST",
"https://api.flare.io/tokens/generate",
json={
"token": "test-token-hello",
},
status_code=200,
)
mocker.register_uri(
"POST",
"https://api.flare.io/hello-post",
json={"foo": "bar"},
status_code=200,
)

client.post("https://api.flare.io/hello-post")
assert mocker.last_request.url == "https://api.flare.io/hello-post"
assert mocker.last_request.headers["Authorization"] == "Bearer test-token-hello"

# GET
with requests_mock.Mocker() as mocker:
mocker.register_uri(
"GET",
"https://api.flare.io/hello-get",
json={"foo": "bar"},
status_code=200,
)

client.get("https://api.flare.io/hello-get")
assert mocker.last_request.url == "https://api.flare.io/hello-get"
assert mocker.last_request.headers["Authorization"] == "Bearer test-token-hello"

# PUT
with requests_mock.Mocker() as mocker:
mocker.register_uri(
"PUT",
"https://api.flare.io/hello-put",
json={"foo": "bar"},
status_code=200,
)

client.put("https://api.flare.io/hello-put")
assert mocker.last_request.url == "https://api.flare.io/hello-put"
assert mocker.last_request.headers["Authorization"] == "Bearer test-token-hello"

# DELETE
with requests_mock.Mocker() as mocker:
mocker.register_uri(
"DELETE",
"https://api.flare.io/hello-delete",
json={"foo": "bar"},
status_code=200,
)

client.delete("https://api.flare.io/hello-delete")
assert mocker.last_request.url == "https://api.flare.io/hello-delete"
assert mocker.last_request.headers["Authorization"] == "Bearer test-token-hello"

0 comments on commit 3ce961e

Please sign in to comment.