add tests for the redis
This commit is contained in:
+39
-3
@@ -4,7 +4,7 @@ import requests_async
|
||||
from httpx import HTTPStatusError
|
||||
|
||||
|
||||
class TestAuth:
|
||||
class TestPermissions:
|
||||
|
||||
async def test_get_access_token_positive(self, target_url:str)->None:
|
||||
|
||||
@@ -15,7 +15,6 @@ class TestAuth:
|
||||
|
||||
assert exc_info.value.response.status_code != 403
|
||||
assert exc_info.value.response.status_code != 401
|
||||
assert exc_info.value.response.status_code != 429
|
||||
|
||||
async def test_get_refresh_token_positive(self, target_url:str)->None:
|
||||
|
||||
@@ -26,7 +25,7 @@ class TestAuth:
|
||||
assert exc_info.value.response.status_code != 403
|
||||
assert exc_info.value.response.status_code != 401
|
||||
|
||||
async def test_get_root_positive(self, target_url:str)->None:
|
||||
async def test_get_root_unauthorized(self, target_url:str)->None:
|
||||
|
||||
with allure.step("get_root"), pytest.raises(HTTPStatusError) as exc_info:
|
||||
|
||||
@@ -45,4 +44,41 @@ class TestAuth:
|
||||
response.raise_for_status()
|
||||
assert exc_info.value.response.status_code != 403
|
||||
assert exc_info.value.response.status_code != 401
|
||||
|
||||
|
||||
class TestRedis:
|
||||
|
||||
@pytest.mark.parametrize("wrong_user_data, expected_status",[
|
||||
pytest.param({"username":"Wrong_user", "password":"Wrong_password"},429,id="Wrong_user_creds")
|
||||
])
|
||||
async def test_rate_limit_positive(self, wrong_user_data:dict, target_url:str, expected_status:int):
|
||||
|
||||
with allure.step("logging with invalid creds"):
|
||||
|
||||
for i in range(5):
|
||||
with pytest.raises(HTTPStatusError) as exc_info:
|
||||
response = await requests_async.post(target_url + "/protected/token", data=wrong_user_data)
|
||||
response.raise_for_status()
|
||||
assert exc_info.value.response.status_code == 401, f"Attempt {i+1} should be 401"
|
||||
|
||||
with allure.step("verify rate_limit works"),pytest.raises(HTTPStatusError) as exc_info:
|
||||
response = await requests_async.post(target_url + "/protected/token", data=wrong_user_data)
|
||||
response.raise_for_status()
|
||||
assert exc_info.value.response.status_code == expected_status
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_user_fixture", [([], [])], indirect=True)
|
||||
async def test_get_logout_revoke_positive(self,test_user_fixture, target_url:str)->None:
|
||||
|
||||
session=test_user_fixture[0]
|
||||
|
||||
with allure.step("logout"):
|
||||
|
||||
response = await session.get(f"{target_url}/protected/logout")
|
||||
response.raise_for_status()
|
||||
|
||||
with allure.step("verify token is revoked"), pytest.raises(HTTPStatusError) as exc_info:
|
||||
response = await session.get(f"{target_url}/protected")
|
||||
response.raise_for_status()
|
||||
assert exc_info.value.response.status_code==429
|
||||
|
||||
Reference in New Issue
Block a user