From 3ce961e5cd7a4b4f6d21332553e59d2e93a0de9f Mon Sep 17 00:00:00 2001 From: aviau Date: Thu, 15 Aug 2024 14:20:39 -0400 Subject: [PATCH] restore test_wrapped_methods --- tests/test_api_client.py | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/test_api_client.py b/tests/test_api_client.py index f6fcc0a..fc4cc97 100644 --- a/tests/test_api_client.py +++ b/tests/test_api_client.py @@ -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"