Skip to content

Commit

Permalink
#22: test: modify AuthClient to be able to create different users
Browse files Browse the repository at this point in the history
  • Loading branch information
ReznikovRoman committed Jul 10, 2022
1 parent b102502 commit 75ce03b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
11 changes: 7 additions & 4 deletions tests/functional/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", {})
Expand Down Expand Up @@ -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):
...
Expand All @@ -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:
Expand Down

0 comments on commit 75ce03b

Please sign in to comment.