-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: sort fixtures to renamed plugins
- Loading branch information
Showing
4 changed files
with
51 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,6 @@ | ||
import os | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from pytest_asyncio import fixture | ||
|
||
from costy.application.common.id_provider import IdProvider | ||
from costy.domain.models.user import UserId | ||
|
||
pytest_plugins = [ | ||
"tests.fixtures.adapters", | ||
"tests.fixtures.infrastructure", | ||
"tests.fixtures.db", | ||
"tests.fixtures.templates", | ||
"tests.fixtures.data", | ||
"tests.fixtures.database", | ||
] | ||
|
||
|
||
@fixture | ||
async def credentials() -> dict[str, str]: # type: ignore | ||
try: | ||
return { | ||
"username": os.environ["TEST_AUTH_USER"], | ||
"password": os.environ["TEST_AUTH_PASSWORD"] | ||
} | ||
except KeyError: | ||
pytest.skip("No test user credentials.") | ||
|
||
|
||
# global is used because tests cannot use a "session" fixed fixture in this case | ||
user_token_state = None | ||
|
||
|
||
@fixture | ||
async def user_token(auth_adapter, credentials): # type: ignore | ||
global user_token_state | ||
if not user_token_state: | ||
response = await auth_adapter.authenticate(credentials["username"], credentials["password"]) | ||
if response: | ||
return response | ||
pytest.skip("Failed to test user authenticate.") | ||
else: | ||
return user_token_state | ||
|
||
|
||
@fixture | ||
async def auth_sub() -> str: # type: ignore | ||
try: | ||
return os.environ["TEST_AUTH_USER_SUB"].replace("auth|0", "") | ||
except KeyError: | ||
pytest.skip("No test user sub environment variable.") | ||
|
||
|
||
@fixture | ||
async def id_provider(user_id: UserId) -> IdProvider: | ||
provider = Mock(spec=IdProvider) | ||
provider.get_current_user_id.return_value = user_id | ||
return provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.