Skip to content

Commit

Permalink
Merge pull request #10 from Flared/aviau/allo
Browse files Browse the repository at this point in the history
split tests
  • Loading branch information
aviau authored Aug 19, 2024
2 parents 4ca283d + e3273b4 commit 3ac18d4
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 251 deletions.
251 changes: 0 additions & 251 deletions tests/test_api_client.py

This file was deleted.

63 changes: 63 additions & 0 deletions tests/test_api_client_creation.py
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()
Loading

0 comments on commit 3ac18d4

Please sign in to comment.