Skip to content

Commit 24502d6

Browse files
feat: add new folder configuration
1 parent 16709b0 commit 24502d6

16 files changed

Lines changed: 121 additions & 15 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ api-batch-test/tests/data/__pycache__/*
1111
api-batch-test/tests/helpers/__pycache__/*
1212
api-batch-test/tests/schemas/__pycache__/*
1313
api-batch-test/config/__pycache__/settings.cpython-314.pyc
14+
reports/html1-report.html

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"python.testing.pytestEnabled": true,
3-
"python.testing.cwd": "${workspaceFolder}/api-batch-test",
4-
"python.testing.pytestArgs": ["tests"]
3+
"python.testing.cwd": "${workspaceFolder}",
4+
"python.testing.pytestArgs": ["api-batch-test/tests"]
55
}

api-batch-test/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ mypy
55
psycopg2-binary
66
jsonschema
77
python-dotenv
8-
vcrpy
9-
pytest-recording
8+
vcrpy
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- application/json
7+
Accept-Encoding:
8+
- gzip, deflate, zstd
9+
Connection:
10+
- keep-alive
11+
User-Agent:
12+
- python-requests/2.32.5
13+
method: GET
14+
uri: https://swapi.dev/api/people/?page=999
15+
response:
16+
body:
17+
string: '{"detail":"Not found"}'
18+
headers:
19+
Allow:
20+
- GET, HEAD, OPTIONS
21+
Connection:
22+
- keep-alive
23+
Content-Type:
24+
- application/json
25+
Date:
26+
- Wed, 03 Dec 2025 17:43:15 GMT
27+
ETag:
28+
- '"8bee5c3ad44d6c57f19e49e8e76ee09e"'
29+
Server:
30+
- nginx/1.16.1
31+
Transfer-Encoding:
32+
- chunked
33+
Vary:
34+
- Accept, Cookie
35+
X-Frame-Options:
36+
- SAMEORIGIN
37+
status:
38+
code: 404
39+
message: NOT FOUND
40+
version: 1
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- application/json
7+
Accept-Encoding:
8+
- gzip, deflate, zstd
9+
Connection:
10+
- keep-alive
11+
User-Agent:
12+
- python-requests/2.32.5
13+
method: GET
14+
uri: https://swapi.dev/api/people/99999/
15+
response:
16+
body:
17+
string: '{"detail":"Not found"}'
18+
headers:
19+
Allow:
20+
- GET, HEAD, OPTIONS
21+
Connection:
22+
- keep-alive
23+
Content-Type:
24+
- application/json
25+
Date:
26+
- Wed, 03 Dec 2025 17:43:14 GMT
27+
ETag:
28+
- '"8bee5c3ad44d6c57f19e49e8e76ee09e"'
29+
Server:
30+
- nginx/1.16.1
31+
Transfer-Encoding:
32+
- chunked
33+
Vary:
34+
- Accept, Cookie
35+
X-Frame-Options:
36+
- SAMEORIGIN
37+
status:
38+
code: 404
39+
message: NOT FOUND
40+
version: 1

api-batch-test/tests/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
from src.api_client import base_url, http
2+
from pathlib import Path
3+
import pytest
24

35
# Re-exporting fixtures from src.api_client
46
__all__ = ["base_url", "http"]
7+
8+
# Diretório onde os cassetes serão salvos/carregados
9+
@pytest.fixture(scope="session")
10+
def vcr_cassette_dir():
11+
# Sempre "tests/cassettes" ao lado deste conftest, independente do cwd
12+
return str(Path(__file__).parent / "cassettes")
13+
14+
@pytest.fixture(scope="session")
15+
def vcr_config():
16+
return {
17+
"filter_headers": ["Authorization"],
18+
"filter_query_parameters": ["api_key", "token"],
19+
"filter_post_data_parameters": ["timestamp"],
20+
"match_on": ["method", "scheme", "host", "port", "path", "query"],
21+
"decode_compressed_response": True,
22+
}
Binary file not shown.
File renamed without changes.
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
# Util para gravar os cassetes VCR, mas em CI continua usando o -record-mode=none para replay.
4+
@pytest.mark.vcr(record_mode="once")
5+
@pytest.mark.negative
6+
@pytest.mark.parametrize(
7+
"path",
8+
[
9+
pytest.param("/people/99999/", id="people-99999"),
10+
pytest.param("/people/?page=999", id="page-999"),
11+
],
12+
)
13+
def test_not_found_or_bounds(http, path):
14+
r = http.get(path)
15+
assert r.status_code in (404, 200)
16+
# Se 200 para page=999 na API pública, valide que results pode estar vazio:
17+
if r.status_code == 200:
18+
assert isinstance(r.json().get("results"), list)

0 commit comments

Comments
 (0)