44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
import os
|
|
import pytest
|
|
from dotenv import load_dotenv
|
|
|
|
import scraper
|
|
|
|
|
|
def test_env_variables_present():
|
|
"""
|
|
Test jestli env proměnné existují a mají obsah
|
|
"""
|
|
load_dotenv()
|
|
|
|
key = (os.getenv("GOOGLE_DEVELOPER_KEY") or "").strip()
|
|
cx = (os.getenv("GOOGLE_CSE_ID") or "").strip()
|
|
assert key, "GOOGLE_DEVELOPER_KEY is missing or empty"
|
|
assert cx, "GOOGLE_CSE_ID is missing or empty"
|
|
|
|
|
|
def test_integration_search_youtube(monkeypatch):
|
|
"""
|
|
Test výsledku vyhledávání "youtube".
|
|
"""
|
|
load_dotenv()
|
|
|
|
key = (os.getenv("GOOGLE_DEVELOPER_KEY") or "").strip()
|
|
cx = (os.getenv("GOOGLE_CSE_ID") or "").strip()
|
|
|
|
if not key or not cx:
|
|
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)
|
|
|
|
results = []
|
|
try:
|
|
results = scraper.get_google_first_page("youtube")
|
|
except RuntimeError as 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)
|