You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.7 KiB
Python
87 lines
2.7 KiB
Python
"""Smoke test for the Indeed adapter.
|
|
|
|
This test opens the Indeed search page and verifies that:
|
|
1. The page loads without error
|
|
2. Job cards are detected OR zero-result state is handled
|
|
3. Card data can be extracted
|
|
|
|
NOTE: This test requires a network connection and Chrome browser.
|
|
Mark with @pytest.mark.network to allow skipping in CI.
|
|
"""
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def indeed_manifest():
|
|
from gimme_job.config import load_site_manifest
|
|
try:
|
|
return load_site_manifest("indeed")
|
|
except FileNotFoundError:
|
|
pytest.skip("indeed.yaml not found")
|
|
|
|
|
|
@pytest.fixture
|
|
def search_query():
|
|
from gimme_job.models.dto import SearchQuery
|
|
return SearchQuery(keywords=["orthodontist"], max_items=10)
|
|
|
|
|
|
def test_indeed_manifest_valid(indeed_manifest):
|
|
"""Manifest parses and has required fields."""
|
|
assert indeed_manifest.site_id == "indeed"
|
|
assert indeed_manifest.identity.base_url
|
|
assert indeed_manifest.identity.start_url_template
|
|
assert indeed_manifest.extract.container_selectors
|
|
|
|
|
|
def test_indeed_adapter_registered():
|
|
"""IndeedAdapter is registered in the registry."""
|
|
from gimme_job.adapters.registry import _load_all_adapters, _REGISTRY
|
|
_load_all_adapters()
|
|
assert "indeed" in _REGISTRY
|
|
|
|
|
|
def test_indeed_url_construction(indeed_manifest, search_query):
|
|
"""Start URL is constructed correctly with keyword encoding."""
|
|
url = indeed_manifest.build_start_url(search_query)
|
|
assert "orthodontist" in url.lower()
|
|
assert "indeed.com" in url
|
|
|
|
|
|
@pytest.mark.network
|
|
def test_indeed_smoke(indeed_manifest, search_query):
|
|
"""Open Indeed search and verify cards or zero-result are detected."""
|
|
from gimme_job.adapters.indeed import IndeedAdapter
|
|
from gimme_job.runtime.browser import BrowserManager
|
|
|
|
adapter = IndeedAdapter(indeed_manifest)
|
|
bm = BrowserManager(headless=True)
|
|
|
|
try:
|
|
context = bm.open_context(headless=True)
|
|
page = context.new_page()
|
|
page.set_default_timeout(15000)
|
|
|
|
url = indeed_manifest.build_start_url(search_query)
|
|
page.goto(url, timeout=30000)
|
|
|
|
# Allow page to settle
|
|
import time
|
|
time.sleep(2)
|
|
|
|
# Collect cards
|
|
cards = adapter.collect_cards(page, indeed_manifest)
|
|
|
|
# Either cards found OR page loaded cleanly (zero results is ok)
|
|
assert isinstance(cards, list), "collect_cards must return a list"
|
|
|
|
if cards:
|
|
# Validate at least 2 fields on first card
|
|
card = cards[0]
|
|
assert card.title and card.title.strip(), "Card must have a title"
|
|
has_second_field = any([card.company, card.location, card.posted_text, card.url])
|
|
assert has_second_field, "Card must have at least one additional field"
|
|
|
|
finally:
|
|
bm.close()
|