43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from iaai_scraper.browser.pace import HumanPacer
|
|
from iaai_scraper.core.config import Settings
|
|
from iaai_scraper.storage.listing import ListingCollector
|
|
|
|
|
|
class _FakePage:
|
|
def __init__(self, counts: dict[str, int]) -> None:
|
|
self._counts = counts
|
|
|
|
class _Locator:
|
|
def __init__(self, count_value: int) -> None:
|
|
self._count_value = count_value
|
|
|
|
def count(self) -> int:
|
|
return self._count_value
|
|
|
|
def locator(self, selector: str) -> "_FakePage._Locator":
|
|
return _FakePage._Locator(self._counts.get(selector, 0))
|
|
|
|
|
|
class TestListingUnit(unittest.TestCase):
|
|
def test_has_next_page_true_for_known_selector(self) -> None:
|
|
page = _FakePage({"a[aria-label*='Next']": 1})
|
|
self.assertTrue(ListingCollector._has_next_page(page))
|
|
|
|
def test_has_next_page_false_when_no_selectors(self) -> None:
|
|
page = _FakePage({})
|
|
self.assertFalse(ListingCollector._has_next_page(page))
|
|
|
|
def test_constructor_with_settings_and_pacer(self) -> None:
|
|
settings = Settings()
|
|
pacer = HumanPacer(settings)
|
|
collector = ListingCollector(settings, pacer)
|
|
self.assertIsNotNone(collector)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|