integration tests

This commit is contained in:
2026-07-30 15:49:08 +03:00
parent f87f54de55
commit 439d57554c
5 changed files with 130 additions and 40 deletions

View File

@@ -13,9 +13,7 @@ from src.service.auth.jwt import Hashes, Jwt
class TestJwt:
@pytest.mark.parametrize("data", [
({"sub": "123"}),
({"sub":""}),
({"":""})
pytest.param({"sub": "123"}, id="full_sub")
])
def test_access_create_positive(self, jwt_service:Jwt, data:dict)->None:
@@ -27,19 +25,19 @@ class TestJwt:
@pytest.mark.parametrize("data",[
("")
@pytest.mark.parametrize("data, expected_exception",[
pytest.param("", AttributeError,id="not_dict_value"),
pytest.param({"sub":""},HTTPException, id="empty_value"),
pytest.param({"":""},HTTPException, id="empty_key_value")
])
def test_access_create_negative(self, jwt_service:Jwt, data:dict)->None:
with allure.step("create invalid access token"),pytest.raises(AttributeError):
def test_access_create_negative(self, jwt_service:Jwt, data:dict, expected_exception)->None:
with allure.step("create invalid access token"),pytest.raises(expected_exception):
jwt_service.create_access_token(data)
@pytest.mark.parametrize("data", [
({"sub": "123"}),
({"sub":""}),
({"":""})
pytest.param({"sub": "123"}, id="full_sub")
])
def test_refresh_create_positive(self, jwt_service:Jwt, data:dict)->None:
@@ -51,16 +49,18 @@ class TestJwt:
assert len(parts)==3
@pytest.mark.parametrize("data",[
("")
@pytest.mark.parametrize("data, expected_exception",[
pytest.param("", AttributeError,id="not_dict_value"),
pytest.param({"sub":""},HTTPException, id="empty_value"),
pytest.param({"":""},HTTPException, id="empty_key_value")
])
def test_refresh_create_negative(self, jwt_service:Jwt, data)->None:
with allure.step("create invalid access token"), pytest.raises(AttributeError):
def test_refresh_create_negative(self, jwt_service:Jwt, data, expected_exception)->None:
with allure.step("create invalid access token"), pytest.raises(expected_exception):
jwt_service.create_refresh_token(data)
@pytest.mark.parametrize("data", [
({"sub": "123", "exp":datetime.now(UTC)+timedelta(minutes=15), "token_type":"access"}),
pytest.param({"sub": "123", "exp":datetime.now(UTC)+timedelta(minutes=15), "token_type":"access"}, id="correct_data"),
])
def test_jwt_decode_positive(self, data:dict, monkeypatch, jwt_service:Jwt)->None:
@@ -77,11 +77,11 @@ class TestJwt:
assert payload.get("token_type")
@pytest.mark.parametrize("data, expected_exception", [
({"sub": "123", "exp":datetime.now(UTC)-timedelta(minutes=15), "token_type":"access"}, HTTPException),
({"sub": "123", "exp":datetime.now(UTC)+timedelta(minutes=15)}, HTTPException),
({"sub": "123", "token_type":"access"}, HTTPException),
({}, HTTPException),
("", AttributeError)
pytest.param({"sub": "123", "exp":datetime.now(UTC)-timedelta(minutes=15), "token_type":"access"}, HTTPException, id="wrong_exp"),
pytest.param({"sub": "123", "exp":datetime.now(UTC)+timedelta(minutes=15)}, HTTPException, id="no_token_type"),
pytest.param({"sub": "123", "token_type":"access"}, HTTPException,id="no_exp"),
pytest.param({}, HTTPException, id="empty_data"),
pytest.param("", AttributeError, id="not_dict_data")
])
def test_jwt_decode_invalid(self,jwt_service:Jwt, expected_exception, data, monkeypatch)->None:
with allure.step("patch a create token function"):
@@ -95,9 +95,9 @@ class TestJwt:
@pytest.mark.parametrize("time, key, algorithm", [
(15, "wrong_key", "HS256"),
(-15, "correct_key", "HS256"),
(15, "correct_key", "HS512"),
pytest.param(15, "wrong_key", "HS256",id="wrong_key"),
pytest.param(-15, "correct_key", "HS256", id="wrong_time"),
pytest.param(15, "correct_key", "HS512", id="wrong_algorithm"),
])
def test_jwt_decode_wrong_env(self, monkeypatch, time:int, key:str, algorithm:str, jwt_service)->None:
@@ -113,7 +113,7 @@ class TestJwt:
@pytest.mark.parametrize("password",[
("plain_password")
pytest.param("plain_password", id="correct_plain_password")
])
def test_hash_and_veryfy_positive(self, password:str, hash_service:Hashes)->None: