Compare commits

..

No commits in common. "04cd85fe59706cea18feeaef117546d18e5b888d" and "f68e9ee218a73cc12e532b5624139435bc91be82" have entirely different histories.

6 changed files with 1 additions and 94 deletions

View File

@ -1,21 +0,0 @@
# Tests
___
## schemathesis
Unter dem Verzeichnis ./src/server/tests befinden sich die Test-Cases, die Max bei der ersten Implementierung der Validierung angelegt hat.
Diese sind derzeit nicht "aktiv", bzw. noch nicht bereinigt.
Ich möchte gern ein automatisches Framework verwenden, das aber nur "manuell" betrieben wird. Änderungen an der API sind selten.
Aktueller Stand (7.1.26):
Im Verzeichnis ./src/server/tests kann folgendes ausgeführt werden:
```pytest -q --maxfail=1 contract/test_openapi_fuzz.py```
Das Ganze funktioniert nur, wenn auch schemathesis und hypothesis in den passenden(!) Versionen im lokalen _venv_ installiert sind.
Aktuell habe ich schemathesis ("latest") und hypothesis 6.120.0:
```pip install "hypothesis==6.120.0"```
Das muss wegen dependencies so blöd gepinnt werden.

View File

@ -1,6 +0,0 @@
[project.optional-dependencies]
test = [
"pytest>=7.0",
"schemathesis>=3.0",
"requests>=2.31",
]

View File

@ -20,4 +20,4 @@ pytest
pytest-cov
coverage
../server/.

View File

@ -1,45 +0,0 @@
import os
import pytest
import requests
@pytest.fixture(scope="session")
def base_url() -> str:
# Example: https://dev.api.mycompany.com
url = os.environ.get("API_BASE_URL")
if not url:
url = "http://neptun.fritz.box"
# raise RuntimeError("Set API_BASE_URL")
return url.rstrip("/")
@pytest.fixture(scope="session")
def login_payload() -> dict[str, str]:
username = os.environ.get("API_USERNAME")
if not username:
username = "Londo"
password = os.environ.get("API_PASSWORD")
if not password:
password = "Hallowach"
# if not username or not password:
# raise RuntimeError("Set API_USERNAME and API_PASSWORD")
return {"username": username, "password": password}
@pytest.fixture(scope="session")
def jwt_token(base_url: str, login_payload: dict[str, str]) -> str:
# Adapt these to your auth endpoint + response shape:
login_path = os.environ.get("API_LOGIN_PATH", "/login")
resp = requests.post(
f"{base_url}{login_path}",
json=login_payload,
timeout=30,
)
resp.raise_for_status()
data = resp.json()
token = data.get("access_token") or data.get("token")
if not token:
raise RuntimeError("Could not find JWT token in login response JSON")
return token
@pytest.fixture(scope="session")
def auth_headers(jwt_token: str) -> dict[str, str]:
return {"Authorization": f"Bearer {jwt_token}"}

View File

@ -1,18 +0,0 @@
import schemathesis
schema = schemathesis.openapi.from_path("../../../misc/BreCalApi.yaml")
@schema.parametrize()
def test_api_conformance(
case,
base_url: str,
auth_headers: dict[str, str],
login_payload: dict[str, str],
) -> None:
# Calls your real service:
if case.path == "/login" and case.method.upper() == "POST":
response = case.call(base_url=base_url, json=login_payload)
else:
response = case.call(base_url=base_url, headers=auth_headers)
# Validates status code, headers, and body against the OpenAPI schema:
case.validate_response(response)

View File

@ -1,3 +0,0 @@
[pytest]
addopts = -ra
testpaths = tests