codex2
This commit is contained in:
0
tests/scraping/__init__.py
Executable file → Normal file
0
tests/scraping/__init__.py
Executable file → Normal file
0
tests/scraping/__pycache__/__init__.cpython-313.pyc
Executable file → Normal file
0
tests/scraping/__pycache__/__init__.cpython-313.pyc
Executable file → Normal file
0
tests/scraping/__pycache__/test_http_fetch.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
0
tests/scraping/__pycache__/test_http_fetch.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
BIN
tests/scraping/__pycache__/test_pipeline.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
BIN
tests/scraping/__pycache__/test_pipeline.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
Binary file not shown.
0
tests/scraping/__pycache__/test_pw_fetch.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
0
tests/scraping/__pycache__/test_pw_fetch.cpython-313-pytest-9.0.2.pyc
Executable file → Normal file
0
tests/scraping/test_http_fetch.py
Executable file → Normal file
0
tests/scraping/test_http_fetch.py
Executable file → Normal file
30
tests/scraping/test_pipeline.py
Executable file → Normal file
30
tests/scraping/test_pipeline.py
Executable file → Normal file
@@ -80,3 +80,33 @@ def test_pipeline_respects_disable_flag():
|
||||
assert product_id is None
|
||||
with get_session(config) as session:
|
||||
assert session.query(Product).count() == 0
|
||||
|
||||
|
||||
def test_pipeline_db_error_adds_note(monkeypatch):
|
||||
"""Une erreur DB ajoute une note et retourne None."""
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
class DummyError(SQLAlchemyError):
|
||||
pass
|
||||
|
||||
def raise_session(*args, **kwargs):
|
||||
raise DummyError("db down")
|
||||
|
||||
monkeypatch.setattr("pricewatch.app.scraping.pipeline.get_session", raise_session)
|
||||
|
||||
snapshot = ProductSnapshot(
|
||||
source="amazon",
|
||||
url="https://example.com/product",
|
||||
fetched_at=datetime(2026, 1, 14, 13, 0, 0),
|
||||
title="Produit",
|
||||
price=10.0,
|
||||
currency="EUR",
|
||||
reference="B08PIPE",
|
||||
debug=DebugInfo(method=FetchMethod.HTTP, status=DebugStatus.SUCCESS),
|
||||
)
|
||||
|
||||
pipeline = ScrapingPipeline(config=FakeAppConfig(db=FakeDbConfig(url="sqlite:///:memory:")))
|
||||
product_id = pipeline.process_snapshot(snapshot, save_to_db=True)
|
||||
|
||||
assert product_id is None
|
||||
assert any("Persistence DB echouee" in note for note in snapshot.debug.notes)
|
||||
|
||||
0
tests/scraping/test_pw_fetch.py
Executable file → Normal file
0
tests/scraping/test_pw_fetch.py
Executable file → Normal file
Reference in New Issue
Block a user