codex2
This commit is contained in:
Binary file not shown.
0
tests/db/__pycache__/test_connection.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
0
tests/db/__pycache__/test_connection.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
BIN
tests/db/__pycache__/test_models.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
BIN
tests/db/__pycache__/test_models.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
Binary file not shown.
0
tests/db/__pycache__/test_repository.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
0
tests/db/__pycache__/test_repository.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
40
tests/db/test_bulk_persistence.py
Normal file
40
tests/db/test_bulk_persistence.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
Tests de charge legere pour la persistence (100 snapshots).
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from pricewatch.app.core.schema import DebugInfo, DebugStatus, FetchMethod, ProductSnapshot
|
||||
from pricewatch.app.db.models import Base, Product
|
||||
from pricewatch.app.db.repository import ProductRepository
|
||||
|
||||
|
||||
def test_bulk_save_100_snapshots():
|
||||
"""Le repository persiste 100 snapshots sans erreur."""
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
Base.metadata.create_all(engine)
|
||||
session = sessionmaker(bind=engine)()
|
||||
|
||||
try:
|
||||
repo = ProductRepository(session)
|
||||
for idx in range(100):
|
||||
snapshot = ProductSnapshot(
|
||||
source="amazon",
|
||||
url=f"https://example.com/product/{idx}",
|
||||
fetched_at=datetime(2026, 1, 14, 14, 0, 0),
|
||||
title=f"Produit {idx}",
|
||||
price=10.0 + idx,
|
||||
currency="EUR",
|
||||
reference=f"REF-{idx}",
|
||||
debug=DebugInfo(method=FetchMethod.HTTP, status=DebugStatus.SUCCESS),
|
||||
)
|
||||
repo.save_snapshot(snapshot)
|
||||
session.commit()
|
||||
|
||||
assert session.query(Product).count() == 100
|
||||
finally:
|
||||
session.close()
|
||||
engine.dispose()
|
||||
0
tests/db/test_connection.py
Executable file → Normal file
0
tests/db/test_connection.py
Executable file → Normal file
7
tests/db/test_models.py
Executable file → Normal file
7
tests/db/test_models.py
Executable file → Normal file
@@ -2,7 +2,7 @@
|
||||
Tests pour les modeles SQLAlchemy.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
@@ -30,6 +30,7 @@ def session() -> Session:
|
||||
yield session
|
||||
finally:
|
||||
session.close()
|
||||
engine.dispose()
|
||||
|
||||
|
||||
def test_product_relationships(session: Session):
|
||||
@@ -42,7 +43,7 @@ def test_product_relationships(session: Session):
|
||||
stock_status="in_stock",
|
||||
fetch_method="http",
|
||||
fetch_status="success",
|
||||
fetched_at=datetime.utcnow(),
|
||||
fetched_at=datetime.now(timezone.utc),
|
||||
)
|
||||
image = ProductImage(image_url="https://example.com/image.jpg", position=0)
|
||||
spec = ProductSpec(spec_key="Couleur", spec_value="Noir")
|
||||
@@ -52,7 +53,7 @@ def test_product_relationships(session: Session):
|
||||
reference="B08N5WRWNW",
|
||||
fetch_method="http",
|
||||
fetch_status="success",
|
||||
fetched_at=datetime.utcnow(),
|
||||
fetched_at=datetime.now(timezone.utc),
|
||||
duration_ms=1200,
|
||||
html_size_bytes=2048,
|
||||
errors={"items": []},
|
||||
|
||||
0
tests/db/test_repository.py
Executable file → Normal file
0
tests/db/test_repository.py
Executable file → Normal file
Reference in New Issue
Block a user