feat: improve SPA scraping and increase test coverage
- Add SPA support for Playwright with wait_for_network_idle and extra_wait_ms - Add BaseStore.get_spa_config() and requires_playwright() methods - Implement AliExpress SPA config with JSON price extraction patterns - Fix Amazon price parsing to prioritize whole+fraction combination - Fix AliExpress regex patterns (remove double backslashes) - Add CLI tests: detect, doctor, fetch, parse, run commands - Add API tests: auth, logs, products, scraping_logs, webhooks Tests: 417 passed, 85% coverage Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
53
tests/api/test_auth_simple.py
Normal file
53
tests/api/test_auth_simple.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""Tests simples pour l'authentification API."""
|
||||
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
from pricewatch.app.api.main import require_token
|
||||
|
||||
|
||||
class FakeConfig:
|
||||
api_token = "valid-token"
|
||||
|
||||
|
||||
class FakeConfigNoToken:
|
||||
api_token = None
|
||||
|
||||
|
||||
def test_require_token_valid(monkeypatch):
|
||||
"""Token valide ne leve pas d'exception."""
|
||||
monkeypatch.setattr("pricewatch.app.api.main.get_config", lambda: FakeConfig())
|
||||
# Ne doit pas lever d'exception
|
||||
require_token("Bearer valid-token")
|
||||
|
||||
|
||||
def test_require_token_missing(monkeypatch):
|
||||
"""Token manquant leve 401."""
|
||||
monkeypatch.setattr("pricewatch.app.api.main.get_config", lambda: FakeConfig())
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
require_token(None)
|
||||
assert exc_info.value.status_code == 401
|
||||
|
||||
|
||||
def test_require_token_invalid_format(monkeypatch):
|
||||
"""Token sans Bearer leve 401."""
|
||||
monkeypatch.setattr("pricewatch.app.api.main.get_config", lambda: FakeConfig())
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
require_token("invalid-format")
|
||||
assert exc_info.value.status_code == 401
|
||||
|
||||
|
||||
def test_require_token_wrong_value(monkeypatch):
|
||||
"""Mauvais token leve 403."""
|
||||
monkeypatch.setattr("pricewatch.app.api.main.get_config", lambda: FakeConfig())
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
require_token("Bearer wrong-token")
|
||||
assert exc_info.value.status_code == 403
|
||||
|
||||
|
||||
def test_require_token_not_configured(monkeypatch):
|
||||
"""Token non configure leve 500."""
|
||||
monkeypatch.setattr("pricewatch.app.api.main.get_config", lambda: FakeConfigNoToken())
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
require_token("Bearer any-token")
|
||||
assert exc_info.value.status_code == 500
|
||||
Reference in New Issue
Block a user