last updates

This commit is contained in:
2025-10-20 21:05:31 +02:00
parent 8d28600318
commit ac52d6eec5
6 changed files with 65 additions and 27 deletions

View File

@@ -1,8 +1,9 @@
import os
import logging
import pytest
from dotenv import load_dotenv
import scraper
import api
def test_env_variables_present():
@@ -13,6 +14,10 @@ def test_env_variables_present():
key = (os.getenv("GOOGLE_DEVELOPER_KEY") or "").strip()
cx = (os.getenv("GOOGLE_CSE_ID") or "").strip()
# Log presence without exposing secrets
logging.info("GOOGLE_DEVELOPER_KEY present: %s", bool(key))
logging.info("GOOGLE_CSE_ID present: %s", bool(cx))
assert key, "GOOGLE_DEVELOPER_KEY is missing or empty"
assert cx, "GOOGLE_CSE_ID is missing or empty"
@@ -27,17 +32,24 @@ def test_integration_search_youtube(monkeypatch):
cx = (os.getenv("GOOGLE_CSE_ID") or "").strip()
if not key or not cx:
logging.warning("Skipping integration test: missing GOOGLE_DEVELOPER_KEY or GOOGLE_CSE_ID")
pytest.skip("Integration test skipped: GOOGLE_DEVELOPER_KEY/GOOGLE_CSE_ID not set")
# Speed up: don't wait during the test
monkeypatch.setattr(scraper, "RATE_SECONDS", 0)
monkeypatch.setattr(scraper, "last_api_call", 0)
monkeypatch.setattr(api, "RATE_SECONDS", 0)
monkeypatch.setattr(api, "last_api_call", 0)
results = []
try:
results = scraper.get_google_first_page("youtube")
logging.info("Calling get_google_first_page for query 'youtube'")
results = api.get_google_first_page("youtube")
logging.info("Received %d results. First title: %s", len(results), (results[0].get("title") if results else None))
except RuntimeError as e:
logging.error("API error during integration test: %s", e)
return pytest.skip(f"Integration test skipped due to API error: {e}")
assert isinstance(results, list) and len(results) > 0
assert any("youtube.com" in (item.get("link") or "") for item in results)
has_youtube = any("youtube.com" in (item.get("link") or "") for item in results)
logging.info("Contains youtube.com link: %s", has_youtube)
assert has_youtube