Testing expires in client
This commit is contained in:
@@ -51,8 +51,6 @@ class Client():
|
|||||||
raise HttpClientException(response.reason, response.status)
|
raise HttpClientException(response.reason, response.status)
|
||||||
|
|
||||||
async def get_auth_headers(self):
|
async def get_auth_headers(self):
|
||||||
if self.expires is not None:
|
|
||||||
logger.trace("DATE COMP: " + str(self.expires <= datetime.now()))
|
|
||||||
if self.expires is None or self.expires <= datetime.now():
|
if self.expires is None or self.expires <= datetime.now():
|
||||||
await self.get_jwt_token()
|
await self.get_jwt_token()
|
||||||
|
|
||||||
|
|||||||
24
tests/test_client.py
Normal file
24
tests/test_client.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import pytest
|
||||||
|
import json
|
||||||
|
from aiohttp import web
|
||||||
|
from aioresponses import aioresponses
|
||||||
|
from rapt.client import Client
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
async def client(aiohttp_client):
|
||||||
|
app = web.Application()
|
||||||
|
# session = await aiohttp_client(app)
|
||||||
|
yield Client("test", "test", None)
|
||||||
|
|
||||||
|
async def test_get_hydrometers(client):
|
||||||
|
with aioresponses() as responses:
|
||||||
|
responses.post("https://id.rapt.io/connect/token", payload=json_reader("./tests/json/token_response.json"), repeat=1)
|
||||||
|
headers1 = await client.get_auth_headers()
|
||||||
|
headers2 = await client.get_auth_headers()
|
||||||
|
|
||||||
|
assert headers1 == headers2
|
||||||
|
|
||||||
|
def json_reader(path):
|
||||||
|
with open(path) as f:
|
||||||
|
return json.load(f)
|
||||||
Reference in New Issue
Block a user