diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..047fdb3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:latest + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["pytest", "tests/"] + diff --git a/checkers/post_v1_account_login.py b/checkers/post_v1_account_login.py index 612629f..529076e 100644 --- a/checkers/post_v1_account_login.py +++ b/checkers/post_v1_account_login.py @@ -16,7 +16,7 @@ class PostV1AccountLogin: @classmethod def check_response_values( cls, - login + login, response ): today = datetime.now().strftime('%Y-%m-%d') diff --git a/config/prod.yaml b/config/prod.yaml new file mode 100644 index 0000000..bb4c239 --- /dev/null +++ b/config/prod.yaml @@ -0,0 +1,7 @@ +service: + dm_api_account: "http://185.185.143.231:5051" + mailhog: "http://185.185.143.231:5025" + +user: + login: "katya_test" + password: "123456" \ No newline at end of file diff --git a/config/stg.yaml b/config/stg.yaml new file mode 100644 index 0000000..bb4c239 --- /dev/null +++ b/config/stg.yaml @@ -0,0 +1,7 @@ +service: + dm_api_account: "http://185.185.143.231:5051" + mailhog: "http://185.185.143.231:5025" + +user: + login: "katya_test" + password: "123456" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4730768..5168bb9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ certifi==2026.1.4 charset-normalizer==3.4.4 colorama==0.4.6 curlify==3.0.0 +distconfig3==1.0.1 idna==3.11 iniconfig==2.3.0 packaging==26.0 @@ -13,9 +14,13 @@ pydantic_core==2.41.5 Pygments==2.19.2 PyHamcrest==2.1.0 pytest==9.0.2 +PyYAML==6.0.3 requests==2.32.5 retrying==1.4.2 structlog==25.5.0 +toml==0.10.2 typing-inspection==0.4.2 typing_extensions==4.15.0 urllib3==2.6.3 +vyper-config==1.2.1 +watchdog==6.0.0 diff --git a/tests/conftest.py b/tests/conftest.py index a963f8c..a332bb6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,7 +6,12 @@ from services.dm_api_account import DMApiAccount from restclient.configuration import Configuration as MailhogConfiguration from restclient.configuration import Configuration as DmApiConfiguration +from vyper import ( + vyper, + v, +) import structlog +from pathlib import Path structlog.configure( processors=[ @@ -17,15 +22,40 @@ ) ] ) + +options = ( + 'service.dm_api_account', + 'service.mailhog', + 'user.login', + 'user.password', +) + +@pytest.fixture(scope="session", autouse=True) +def set_config(request): + config = Path(__file__).joinpath("../../").joinpath("config") + config_name = request.config.getoption("--env") + v.set_config_name(config_name) + v.add_config_path(config) + v.read_in_config() + for option in options: + v.set(f"{option}", request.config.getoption(f"--{option}")) + +def pytest_addoption(parser): + parser.addoption("--env", action="store", default="stg", help="run stg") + + for option in options: + parser.addoption(f"--{option}", action="store", default=None) + + @pytest.fixture(scope="function") def mailhog_api(): - mailhog_configuration = MailhogConfiguration(host='http://185.185.143.231:5025') + mailhog_configuration = MailhogConfiguration(host=v.get("service.mailhog"), disable_log=False) mailhog_client = MailHogApi(configuration=mailhog_configuration) return mailhog_client @pytest.fixture(scope="function") def account_api(): - dm_api_configuration = DmApiConfiguration(host='http://185.185.143.231:5051', disable_log=False) + dm_api_configuration = DmApiConfiguration(host=v.get("service.dm_api_account"), disable_log=False) account = DMApiAccount(configuration=dm_api_configuration) return account @@ -36,22 +66,22 @@ def account_helper(account_api, mailhog_api): @pytest.fixture(scope="function") def auth_account_helper(mailhog_api): - dm_api_configuration = DmApiConfiguration(host='http://185.185.143.231:5051', disable_log=False) + dm_api_configuration = DmApiConfiguration(host=v.get("service.dm_api_account"), disable_log=False) account = DMApiAccount(configuration=dm_api_configuration) account_helper = AccountHelper(dm_account_api=account, mailhog=mailhog_api) account_helper.auth_client( - login = "katya_test", - password = "123456" + login = v.get("user.login"), + password = v.get("user.password") ) return account_helper @pytest.fixture() def prepare_user(): now = datetime.now() - data = now.strftime("%d_%m_%Y_%H_%M_%S") + data = now.strftime("%d_%m_%Y_%H_%M_%S_%f")[:-3] login = f'katya_test{data}' email = f'{login}@mail.ru' - password = '123456' + password = v.get("user.password") User = namedtuple("user", ["login", "password", "email"]) user = User(login=login, password=password, email=email) return user \ No newline at end of file diff --git a/tests/functional/get_v1_account/test_get_v1_account.py b/tests/functional/get_v1_account/test_get_v1_account.py index 804651c..7bd9347 100644 --- a/tests/functional/get_v1_account/test_get_v1_account.py +++ b/tests/functional/get_v1_account/test_get_v1_account.py @@ -12,7 +12,7 @@ def test_get_v1_account_auth(auth_account_helper): assert_that(response.resource.online).is_instance_of(datetime) assert_that(response.resource.roles).contains(UserRole.GUEST, UserRole.PLAYER) - GetV1Account.check_response_values(response) + GetV1Account.check_response_values(response=response, login="katya_test") def test_get_v1_account_no_auth(account_helper): with check_status_code_http(401, "User must be authenticated"): diff --git a/tests/functional/post_v1_account_login/test_post_v1_account_login.py b/tests/functional/post_v1_account_login/test_post_v1_account_login.py index d7ccbf5..014010f 100644 --- a/tests/functional/post_v1_account_login/test_post_v1_account_login.py +++ b/tests/functional/post_v1_account_login/test_post_v1_account_login.py @@ -9,7 +9,7 @@ def test_post_v1_account_login(prepare_user, account_helper): account_helper.register_new_user(login=login, password=password, email=email) response = account_helper.user_login(login=login, password=password, validate_response=True) - PostV1AccountLogin.check_response_values(response) + PostV1AccountLogin.check_response_values(response=response, login=login)