Skip to content

Commit cde3cfd

Browse files
authored
Merge pull request #1 from ZhikharevAl/tests/tests
added test users
2 parents 56f99bd + d6222ca commit cde3cfd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1696
-0
lines changed

.github/workflows/ruff_check.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Ruff Linter
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v4
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: '3.12.4'
17+
18+
- name: Install Ruff
19+
run: pip install ruff
20+
21+
- name: Run Ruff
22+
run: ruff check

.github/workflows/run_tests.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Playwright Tests
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test-release:
8+
name: Run tests on Release environment
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Install uv
14+
uses: astral-sh/setup-uv@v3
15+
with:
16+
version: "0.4.27"
17+
enable-cache: true
18+
cache-dependency-glob: "requirements**.txt"
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.12.7'
24+
25+
- name: Install dependencies
26+
run: |
27+
uv pip install --system -r requirements.txt
28+
29+
- name: Ensure browsers are installed
30+
run: uv pip install --system playwright && python -m playwright install --with-deps
31+
32+
- name: Set environment for Release
33+
run: |
34+
echo "BASE_URL=https://release-gs.qa-playground.com/api/v1/" >> $GITHUB_ENV
35+
36+
- name: Run tests for Release
37+
run: |
38+
mkdir -p test-results/release
39+
pytest --alluredir=allure-results/release
40+
41+
- name: Upload Playwright traces for Release
42+
if: always()
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: playwright-traces-release
46+
path: test-results/release/
47+
retention-days: 20
48+
49+
- uses: actions/upload-artifact@v4
50+
with:
51+
name: allure-results-release
52+
path: allure-results/release
53+
retention-days: 20
54+
55+
test-dev:
56+
name: Run tests on Dev environment
57+
runs-on: ubuntu-latest
58+
needs: test-release
59+
steps:
60+
- uses: actions/checkout@v4
61+
62+
- name: Install uv
63+
uses: astral-sh/setup-uv@v3
64+
with:
65+
version: "0.4.27"
66+
enable-cache: true
67+
cache-dependency-glob: "requirements**.txt"
68+
69+
- name: Set up Python
70+
uses: actions/setup-python@v5
71+
with:
72+
python-version: '3.12.7'
73+
74+
- name: Install dependencies
75+
run: |
76+
uv pip install --system -r requirements.txt
77+
78+
- name: Ensure browsers are installed
79+
run: uv pip install --system playwright && python -m playwright install --with-deps
80+
81+
- name: Set environment for Dev
82+
run: |
83+
echo "BASE_URL=https://dev-gs.qa-playground.com/api/v1/" >> $GITHUB_ENV
84+
85+
- name: Run tests for Dev
86+
run: |
87+
mkdir -p test-results/dev
88+
pytest --alluredir=allure-results/dev
89+
90+
- name: Upload Playwright traces for Dev
91+
if: always()
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: playwright-traces-dev
95+
path: test-results/dev/
96+
retention-days: 20
97+
98+
- uses: actions/upload-artifact@v4
99+
with:
100+
name: allure-results-dev
101+
path: allure-results/dev
102+
retention-days: 20
103+
104+
merge-allure-reports:
105+
name: Merge Allure Reports
106+
runs-on: ubuntu-latest
107+
needs: [test-release, test-dev]
108+
steps:
109+
- name: Download Allure results for Release
110+
uses: actions/download-artifact@v3
111+
with:
112+
name: allure-results-release
113+
path: allure-results/release
114+
115+
- name: Download Allure results for Dev
116+
uses: actions/download-artifact@v3
117+
with:
118+
name: allure-results-dev
119+
path: allure-results/dev
120+
121+
- name: Merge Allure results
122+
run: |
123+
allure generate allure-results/release allure-results/dev -o merged-allure-report
124+
125+
- name: Deploy Allure report to Github Pages
126+
uses: peaceiris/actions-gh-pages@v2
127+
env:
128+
PERSONAL_TOKEN: ${{ secrets.HACK }}
129+
PUBLISH_BRANCH: gh-pages
130+
PUBLISH_DIR: merged-allure-report

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Environment variables
2+
.env
3+
4+
# Python
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# Testing
10+
.pytest_cache/
11+
allure-results/
12+
allure-report/
13+
pytest.log
14+
15+
/.venv
16+
/.vscode
17+
/test-results

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
repos:
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.7.4
5+
hooks:
6+
- id: ruff
7+
args: [--fix]
8+
- id: ruff-format
9+
10+
- repo: https://github.com/pre-commit/pre-commit-hooks
11+
rev: v4.0.1
12+
hooks:
13+
- id: trailing-whitespace
14+
- id: end-of-file-fixer
15+
- id: check-yaml

config/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# noqa: D104

config/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TIMEOUT = 30000

conftest.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import logging
2+
import os
3+
from collections.abc import Generator
4+
from typing import Any
5+
6+
import pytest
7+
from dotenv import load_dotenv
8+
from playwright.sync_api import APIRequestContext, Playwright
9+
10+
from services.games.games_api_client import GamesAPIClient
11+
from services.users.user_api_client import UserAPIClient
12+
13+
load_dotenv()
14+
15+
16+
@pytest.fixture(scope="session")
17+
def api_request_context(
18+
playwright: Playwright,
19+
) -> Generator[APIRequestContext, None, None]:
20+
"""Context for executing API requests."""
21+
headers = {
22+
"Authorization": f"Bearer {os.getenv('API_TOKEN')}",
23+
"Content-Type": "application/json",
24+
}
25+
base_url = os.getenv("BASE_URL", "https://default-url.com/api/v1/")
26+
27+
request_context: APIRequestContext = playwright.request.new_context(
28+
base_url=base_url,
29+
extra_http_headers=headers,
30+
)
31+
yield request_context
32+
request_context.dispose()
33+
34+
35+
@pytest.fixture
36+
def user_api_client(api_request_context: APIRequestContext) -> UserAPIClient:
37+
"""User API client."""
38+
return UserAPIClient(api_request_context)
39+
40+
41+
@pytest.fixture
42+
def game_api_client(api_request_context: APIRequestContext) -> GamesAPIClient:
43+
"""Games API client."""
44+
return GamesAPIClient(api_request_context)
45+
46+
47+
@pytest.fixture(params=["api-3", "api-22"])
48+
def new_user(
49+
user_api_client: UserAPIClient, request: pytest.FixtureRequest
50+
) -> Generator[dict[str, Any], Any, None]:
51+
"""
52+
A fixture for creating a new user that will be automatically deleted after the test.
53+
54+
:param user_api_client: A client for working with the user API
55+
:param request: Fixture request object, used for parametrization
56+
"""
57+
task_id = request.param
58+
user = user_api_client.create_user(task_id)
59+
60+
yield user
61+
62+
try:
63+
user_api_client.delete_user(str(user["uuid"]), task_id)
64+
except Exception as e:
65+
error_message = f"The user could not be deleted {user['uuid']}: {e}"
66+
logging.exception(error_message)
67+
68+
69+
def pytest_configure() -> None:
70+
"""Log configuration."""
71+
logging.basicConfig(
72+
level=logging.INFO,
73+
format="%(asctime)s [%(levelname)s] %(message)s",
74+
datefmt="%Y-%m-%d %H:%M:%S",
75+
)
76+
logging.getLogger("faker").setLevel(logging.WARNING)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
---
3+
4+
# Bug Report [for the test case 001](/docs/TestCases/Test_case_001_Verify%20User%20List.md)
5+
6+
**ID**: BUG-001
7+
**Title**: API Fails to Validate User List and Offset Functionality
8+
9+
---
10+
11+
## Description
12+
13+
The test cases for the Users API are failing under certain conditions. Specifically, the `meta.total` value is not greater than 0 when users are present, and the first user from the initial list appears in the second list when using an offset.
14+
15+
---
16+
17+
## Steps to Reproduce
18+
19+
1. Send a `GET /users` request with `Task-Id` set to `api-21`.
20+
2. Verify the `meta.total` field in the response.
21+
3. Send a `GET /users` request with `Task-Id` set to `api-6` and an offset of 10.
22+
4. Verify that the first user from the initial list is not present in the second list.
23+
24+
---
25+
26+
## Expected Result
27+
28+
1. The `meta.total` field should be greater than 0 if there are users present.
29+
2. The first user from the initial list should not be present in the second list when using an offset of 10.
30+
31+
---
32+
33+
## Actual Result
34+
35+
1. `meta.total` is not greater than 0 even when users are present (Task-Id: api-21).
36+
2. The first user from the initial list is present in the second list with an offset of 10 (Task-Id: api-6).
37+
38+
---
39+
40+
## Logs/Error Messages
41+
42+
- `FAILED tests/test_users.py::TestUsersAPI::test_get_users[api-21] - AssertionError: Meta 'total' should be greater than 0 for Task-Id api-21`
43+
- `FAILED tests/test_users.py::TestUsersAPI::test_get_users[api-6] - AssertionError: First user UUID 2ed46da7-2d96-4da2-af16-74dfc34174ca from initial list should not be present in the second list with offset=10`
44+
45+
---
46+
47+
## Additional Information
48+
49+
- Ensure that the `meta.total` field correctly reflects the number of users.
50+
- Verify that pagination and offset functionality work as expected and that the first user from the initial list does not appear in the subsequent pages when using an offset.
51+
52+
---
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
---
3+
4+
# Bug Report [for the test case 002](/docs/TestCases/Test_CaseVerify_Single_UserRetrieval_002.md)
5+
6+
**ID**: BUG-002
7+
**Title**: API Returns Incorrect User for Requested UUID
8+
9+
---
10+
11+
## Description
12+
13+
When requesting a specific user by UUID, the API returns a different user's details than the one requested.
14+
15+
---
16+
17+
## Steps to Reproduce
18+
19+
1. Send a `GET /users` request with the following parameters:
20+
- Task-Id: api-23
21+
- User UUID: 23403afa-483c-4803-8af1-2d1316f1460f
22+
23+
2. Verify the returned user's UUID
24+
25+
---
26+
27+
## Expected Result
28+
29+
The API should return a user with the UUID 23403afa-483c-4803-8af1-2d1316f1460f
30+
31+
---
32+
33+
## Actual Result
34+
35+
The API returns a user with a different UUID:
36+
37+
- Requested UUID: 23403afa-483c-4803-8af1-2d1316f1460f
38+
- Returned UUID: 2ed46da7-2d96-4da2-af16-74dfc34174ca
39+
40+
---
41+
42+
## Impact
43+
44+
High - This indicates a critical issue with the user retrieval endpoint, where the API is not correctly filtering users by their UUID.
45+
46+
---
47+
48+
## Recommended Actions
49+
50+
1. Investigate the user retrieval logic in the backend
51+
2. Verify the database query or filtering mechanism
52+
3. Ensure that the API correctly matches and returns the user with the exact requested UUID
53+
54+
---
55+
56+
## Additional Notes
57+
58+
- The test case uses Pydantic validation to ensure the response structure
59+
- All expected keys are present in the returned user object
60+
- The discrepancy is solely in the UUID matching
61+
62+
---

0 commit comments

Comments
 (0)