-
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.
#22: test: modify AuthClient to be able to create different users
- Loading branch information
1 parent
b102502
commit 75ce03b
Showing
2 changed files
with
14 additions
and
4 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 |
---|---|---|
|
@@ -39,6 +39,13 @@ async def auth_client() -> APIClient: | |
await auth_client_.close() | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
async def another_auth_client() -> APIClient: | ||
auth_client_ = create_auth_client(user_email="[email protected]") | ||
yield auth_client_ | ||
await auth_client_.close() | ||
|
||
|
||
@pytest.fixture | ||
def settings() -> Test: | ||
return settings_ | ||
|
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 |
---|---|---|
|
@@ -31,13 +31,16 @@ class APIClient(ClientSession): | |
def __init__( | ||
self, | ||
base_url: str | None = settings.SERVER_BASE_URL, | ||
use_authorization: bool | None = False, | ||
use_authorization: bool | None = False, user_email: str | None = None, | ||
*args, **kwargs, | ||
): | ||
super().__init__(base_url, *args, **kwargs) | ||
self.base_url = base_url | ||
self.use_authorization = use_authorization | ||
self.auth_url = settings.NETFLIX_AUTH_BASE_URL | ||
if user_email is None: | ||
user_email = "[email protected]" | ||
self.user_email = user_email | ||
|
||
async def _request(self, method, url, *args, **kwargs): | ||
headers = kwargs.pop("headers", {}) | ||
|
@@ -102,7 +105,7 @@ async def get_access_token(self) -> str: | |
return await self._get_access_token() | ||
|
||
async def _get_access_token(self) -> str: | ||
body = {"email": "[email protected]", "password": "pass"} | ||
body = {"email": self.user_email, "password": "pass"} | ||
async with aiohttp.ClientSession() as session: | ||
async with session.post(urljoin(self.auth_url, "/api/v1/auth/register"), data=body): | ||
... | ||
|
@@ -118,8 +121,8 @@ def create_anon_client() -> APIClient: | |
return APIClient(base_url=settings.CLIENT_BASE_URL) | ||
|
||
|
||
def create_auth_client() -> APIClient: | ||
return APIClient(base_url=settings.CLIENT_BASE_URL, use_authorization=True) | ||
def create_auth_client(user_email: str | None = None) -> APIClient: | ||
return APIClient(base_url=settings.CLIENT_BASE_URL, use_authorization=True, user_email=user_email) | ||
|
||
|
||
async def run_redis_migrations() -> None: | ||
|