|
6 | 6 |
|
7 | 7 |
|
8 | 8 | class AuthClient: |
9 | | - def __init__(self, playwright: Playwright, settings: Settings): |
10 | | - self.request_context = playwright.request.new_context(base_url=settings.client_base_url) |
11 | | - |
12 | | - def login(self, user_credentials: dict) -> dict: |
13 | | - with allure.step("Authenticate user through Login API"): |
14 | | - response = self.request_context.post( |
15 | | - "/api/ecom/auth/login", |
16 | | - data={ |
17 | | - "userEmail": user_credentials["userEmail"], |
18 | | - "userPassword": user_credentials["userPassword"], |
19 | | - }, |
20 | | - ) |
21 | | - |
22 | | - assert_status(response, 200, "Login API") |
23 | | - response_body = response.json() |
24 | | - assert_json_has_keys(response_body, ["token"], "Login API") |
25 | | - return response_body |
26 | | - |
27 | | - def get_token(self, user_credentials: dict) -> str: |
| 9 | + def __init__(self, request_context): |
| 10 | + self.request_context = request_context |
| 11 | + |
| 12 | + def login(self, user_credentials): |
| 13 | + last_error = None |
| 14 | + |
| 15 | + for attempt in range(3): |
| 16 | + try: |
| 17 | + response = self.request_context.post( |
| 18 | + "/api/ecom/auth/login", |
| 19 | + data=user_credentials, |
| 20 | + ) |
| 21 | + assert_status(response, 200, "Login API") |
| 22 | + return response.json() |
| 23 | + |
| 24 | + except PlaywrightError as error: |
| 25 | + last_error = error |
| 26 | + if attempt == 2: |
| 27 | + raise |
| 28 | + time.sleep(2) |
| 29 | + |
| 30 | + raise last_error |
| 31 | + |
| 32 | + def get_token(self, user_credentials): |
28 | 33 | return self.login(user_credentials)["token"] |
29 | 34 |
|
30 | 35 | def login_with_payload(self, payload: dict): |
|
0 commit comments