97 lines
2.3 KiB
Python
97 lines
2.3 KiB
Python
"""Pytest configuration for json-to-openapi tests."""
|
|
import pytest
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_simple_json():
|
|
return {"name": "John", "age": 30, "active": True}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_nested_json():
|
|
return {
|
|
"id": 1,
|
|
"name": "Product",
|
|
"price": 29.99,
|
|
"in_stock": True,
|
|
"tags": ["electronics", "sale"],
|
|
"metadata": {
|
|
"created_at": "2024-01-15",
|
|
"updated_at": "2024-01-20"
|
|
}
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_array_json():
|
|
return [
|
|
{"id": 1, "name": "Item 1"},
|
|
{"id": 2, "name": "Item 2"},
|
|
{"id": 3, "name": "Item 3"}
|
|
]
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_complex_json(tmp_path):
|
|
data = {
|
|
"users": [
|
|
{
|
|
"id": 1,
|
|
"name": "Alice",
|
|
"email": "alice@example.com",
|
|
"active": True,
|
|
"scores": [95, 87, 92],
|
|
"address": {
|
|
"street": "123 Main St",
|
|
"city": "Boston",
|
|
"zip": "02101"
|
|
}
|
|
},
|
|
{
|
|
"id": 2,
|
|
"name": "Bob",
|
|
"email": "bob@example.com",
|
|
"active": False,
|
|
"scores": [78, 85, 80],
|
|
"address": {
|
|
"street": "456 Oak Ave",
|
|
"city": "Cambridge",
|
|
"zip": "02139"
|
|
}
|
|
}
|
|
],
|
|
"total": 2
|
|
}
|
|
file_path = tmp_path / "complex.json"
|
|
file_path.write_text(json.dumps(data))
|
|
return file_path
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_datetime_json(tmp_path):
|
|
data = {
|
|
"created_at": "2024-01-15T10:30:00Z",
|
|
"updated_at": "2024-01-20T14:45:30",
|
|
"event_date": "2024-03-01"
|
|
}
|
|
file_path = tmp_path / "datetime.json"
|
|
file_path.write_text(json.dumps(data))
|
|
return file_path
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_json_dir(tmp_path):
|
|
"""Create a temporary directory with sample JSON files."""
|
|
dir_path = tmp_path / "json_files"
|
|
dir_path.mkdir()
|
|
|
|
simple = dir_path / "simple.json"
|
|
simple.write_text('{"name": "Test", "value": 42}')
|
|
|
|
nested = dir_path / "nested.json"
|
|
nested.write_text('{"data": {"items": [1, 2, 3]}}')
|
|
|
|
return dir_path
|