fix: resolve CI test failures
Some checks failed
CI / test (push) Failing after 10s
CI / lint (push) Failing after 5s
CI / type-check (push) Failing after 6s

- Added missing fixtures for api_snapshot tests in conftest.py
- Added PYTHONPATH to CI workflow for module discovery
This commit is contained in:
2026-02-04 15:05:43 +00:00
parent 9ec7a07619
commit 926c86ea6f

View File

@@ -20,14 +20,14 @@ def temp_dir():
def sample_package_json(): def sample_package_json():
"""Create a sample package.json file content.""" """Create a sample package.json file content."""
return """{ return """{
\"name\": \"test-project\", "name": "test-project",
\"version\": \"1.0.0\", "version": "1.0.0",
\"dependencies\": { "dependencies": {
\"express\": \"4.18.2\", "express": "4.18.2",
\"lodash\": \"4.17.20\" "lodash": "4.17.20"
}, },
\"devDependencies\": { "devDependencies": {
\"jest\": \"29.7.0\" "jest": "29.7.0"
} }
}""" }"""
@@ -61,13 +61,13 @@ def sample_cargo_toml():
"""Create a sample Cargo.toml file content.""" """Create a sample Cargo.toml file content."""
return """ return """
[package] [package]
name = \"my-project\" name = "my-project"
version = \"0.1.0\" version = "0.1.0"
edition = \"2021\" edition = "2021"
[dependencies] [dependencies]
serde = \"1.0\" serde = "1.0"
tokio = \"1.36\" tokio = "1.36"
""" """
@@ -135,3 +135,103 @@ def sample_outdated_dependencies():
def empty_scan_result(): def empty_scan_result():
"""Create an empty scan result.""" """Create an empty scan result."""
return ScanResult() return ScanResult()
@pytest.fixture
def sample_request():
"""Create a sample recorded request."""
from api_snapshot.recorder.recorder import RecordedRequest
return RecordedRequest(
method="GET",
url="https://api.example.com/users",
headers={"Accept": "application/json"},
body=None,
)
@pytest.fixture
def sample_response():
"""Create a sample recorded response."""
from api_snapshot.recorder.recorder import RecordedResponse
return RecordedResponse(
status_code=200,
headers={"Content-Type": "application/json"},
body='{"success": true}',
latency_ms=150,
)
@pytest.fixture
def sample_pair(sample_request, sample_response):
"""Create a sample request-response pair."""
from api_snapshot.recorder.recorder import RequestResponsePair
return RequestResponsePair(
request=sample_request,
response=sample_response,
)
@pytest.fixture
def sample_snapshot(sample_pair):
"""Create a sample snapshot."""
from api_snapshot.snapshot.manager import Snapshot, SnapshotMetadata
meta = SnapshotMetadata(description="Test snapshot")
return Snapshot(metadata=meta, requests=[sample_pair])
@pytest.fixture
def sample_snapshot_dict():
"""Create a sample snapshot dictionary."""
return {
"metadata": {
"version": "1.0",
"timestamp": "2024-01-01T00:00:00",
"description": "Test snapshot",
"source_url": "https://api.example.com",
"latency_mode": "original",
"custom_latency_ms": None,
"tags": []
},
"requests": [
{
"request": {
"method": "GET",
"url": "https://api.example.com/users",
"headers": {"Accept": "application/json"},
"body": None,
"timestamp": "2024-01-01T00:00:00"
},
"response": {
"status_code": 200,
"headers": {"Content-Type": "application/json"},
"body": '{"success": true}',
"latency_ms": 150
}
}
]
}
@pytest.fixture
def snapshot_manager(temp_dir):
"""Create a snapshot manager with a test snapshot."""
from api_snapshot.snapshot.manager import SnapshotManager
manager = SnapshotManager(temp_dir)
return manager
@pytest.fixture
def snapshot_file(temp_dir, sample_pair):
"""Create a snapshot file for testing."""
from api_snapshot.snapshot.manager import SnapshotManager
import json
manager = SnapshotManager(temp_dir)
manager.save_snapshot(
name="test_snapshot",
requests=[sample_pair, sample_pair],
description="Test snapshot"
)
path = manager._get_path("test_snapshot")
return path