-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Flared/aviau/allo
split tests
- Loading branch information
Showing
5 changed files
with
265 additions
and
251 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import pytest | ||
import requests_mock | ||
|
||
from .utils import get_test_client | ||
from datetime import datetime | ||
from flareio import FlareApiClient | ||
from flareio.exceptions import TokenError | ||
|
||
|
||
def test_create_client() -> None: | ||
FlareApiClient(api_key="test") | ||
|
||
|
||
def test_create_client_empty_api_key() -> None: | ||
with pytest.raises(Exception, match="API Key cannot be empty."): | ||
FlareApiClient( | ||
api_key="", | ||
) | ||
|
||
|
||
def test_generate_token() -> None: | ||
client = get_test_client(authenticated=False) | ||
assert client._api_token is None | ||
assert client._api_token_exp is None | ||
with requests_mock.Mocker() as mocker: | ||
mocker.register_uri( | ||
"POST", | ||
"https://api.flare.io/tokens/generate", | ||
json={ | ||
"token": "test-token-hello", | ||
}, | ||
status_code=200, | ||
) | ||
|
||
token = client.generate_token() | ||
assert token == "test-token-hello" | ||
|
||
assert client._api_token == "test-token-hello" | ||
assert client._api_token_exp | ||
assert client._api_token_exp >= datetime.now() | ||
|
||
assert mocker.last_request.url == "https://api.flare.io/tokens/generate" | ||
assert mocker.last_request.text is None | ||
assert mocker.last_request.headers["Authorization"] == "test-api-key" | ||
|
||
|
||
def test_generate_token_error() -> None: | ||
client = get_test_client(authenticated=False) | ||
assert client._api_token is None | ||
assert client._api_token_exp is None | ||
|
||
with requests_mock.Mocker() as mocker: | ||
mocker.register_uri( | ||
"POST", | ||
"https://api.flare.io/tokens/generate", | ||
json={ | ||
"error": {}, | ||
}, | ||
status_code=400, | ||
) | ||
|
||
with pytest.raises(TokenError): | ||
client.generate_token() |
Oops, something went wrong.