-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/auth tests api (CORE-13484) #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b7213d9
bc31a9c
9d0b44a
be7cf76
8613be7
fa645ff
080994e
a036884
8a38c19
77b7a46
8d2ceb1
572a6d7
3a5d867
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import pytest | ||
| from utils.api_client import NodesAPIClient, InternalAPIClient | ||
| from clients.api_client import NodesAPIClient, InternalAPIClient, AuthAPIClient | ||
| from config.settings import Settings | ||
| from faker import Faker | ||
|
|
||
| fake = Faker() | ||
| @pytest.fixture(scope="session") | ||
| def faker(): | ||
| return Faker() | ||
|
|
||
| @pytest.fixture(scope="session") | ||
| def nodes_api_client(config: Settings): | ||
|
|
@@ -19,16 +21,65 @@ def internal_api_client(config: Settings): | |
| client.close() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def authenticated_client(config: Settings): | ||
| @pytest.fixture(scope="session") | ||
| def authenticated_nodes_client(config: Settings): | ||
| client = NodesAPIClient(config) | ||
| yield client | ||
| client.close() | ||
|
|
||
| @pytest.fixture | ||
| def invalid_username(): | ||
| return fake.email() | ||
|
|
||
| @pytest.fixture(scope="function") | ||
| def auth_client(config: Settings): | ||
| client = AuthAPIClient(config) | ||
| yield client | ||
| client.close() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def authenticated_auth_client(config: Settings): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiple tests modify client.token, client.headers, call logout(), etc. With session scope, one test's modifications affect all subsequent tests.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically after check with modified token/headers it returns to valid state, but in any case i'll add func scope. |
||
| client = AuthAPIClient(config) | ||
| if config.user_log and config.user_pass: | ||
| response = client.login(config.user_log, config.user_pass) | ||
| if response.status_code == 200: | ||
| token = response.json().get("access_token") | ||
| refresh_token = response.json().get("refresh_token") | ||
| client.token = token | ||
| client.refresh_token = refresh_token | ||
| else: | ||
| raise Exception("Login failed") | ||
| yield client | ||
| client.close() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def invalid_password(): | ||
| return fake.password() | ||
| def valid_credentials(config: Settings): | ||
| return { | ||
| "username": config.user_log, | ||
| "password": config.user_pass | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def invalid_username(faker): | ||
| return faker.email() | ||
|
|
||
| @pytest.fixture(scope="function") | ||
| def valid_username(faker): | ||
| return faker.name() | ||
|
|
||
| @pytest.fixture(scope="function") | ||
| def valid_password(faker): | ||
| return faker.password() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def invalid_password(faker): | ||
| return faker.password() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def invalid_credentials(invalid_username, invalid_password): | ||
| return { | ||
| "username": invalid_username, | ||
| "password": invalid_password | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
methods like get(), post() accept optional headers, but send_custom_request() doesn't.