TirSystem/git-workflows: OpenGrep / opengrep (push) Skipped
TirSystem/git-workflows: Publish wiki / publish-wiki (push) Skipped
TirSystem/git-workflows: Sync GitHub mirror metadata / sync-metadata (push) Skipped
TirSystem/git-workflows: Publish accepted milestones / publish (push) Skipped
TirSystem/git-workflows: Validate / validate (push) Skipped
TirSystem/git-workflows: Validate / validate (pull_request) Successful in 42s
TirSystem/git-workflows: OpenGrep / opengrep (pull_request) Successful in 4m48s
Selenium bot (src/tinder_bot) for the Day 50 lecture steps, unit tests, a mock-site Docker e2e harness for screenshots, and README plus wiki in English, Danish and Bahasa Malaysia.
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
from selenium.common.exceptions import (
|
|
ElementClickInterceptedException,
|
|
NoSuchElementException,
|
|
)
|
|
|
|
from tinder_bot import locators
|
|
from tinder_bot.config import Settings
|
|
from tinder_bot.steps import like_once, like_profiles
|
|
|
|
|
|
def test_like_once_retries_while_loading() -> None:
|
|
driver = MagicMock()
|
|
button = MagicMock()
|
|
driver.find_element.side_effect = [NoSuchElementException(), button]
|
|
pauses: list[float] = []
|
|
|
|
like_once(driver, Settings(), pauses.append)
|
|
|
|
button.click.assert_called_once()
|
|
assert pauses == [2.0]
|
|
|
|
|
|
def test_like_once_dismisses_match_popup() -> None:
|
|
driver = MagicMock()
|
|
like, back = MagicMock(), MagicMock()
|
|
like.click.side_effect = [ElementClickInterceptedException(), None]
|
|
driver.find_element.side_effect = lambda by, value: (
|
|
back if value == locators.BACK_TO_TINDER[1] else like
|
|
)
|
|
|
|
like_once(driver, Settings(), lambda _: None)
|
|
|
|
back.click.assert_called_once()
|
|
assert like.click.call_count == 2
|
|
|
|
|
|
def test_like_profiles_stops_at_max_and_pauses_between_likes() -> None:
|
|
driver = MagicMock()
|
|
pauses: list[float] = []
|
|
|
|
liked = like_profiles(driver, Settings(max_likes=3), pauses.append)
|
|
|
|
assert liked == 3
|
|
assert pauses == [1.5, 1.5, 1.5]
|
|
|
|
|
|
def test_settings_from_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("MAX_LIKES", "5")
|
|
monkeypatch.setenv("FACEBOOK_EMAIL", "a@b.c")
|
|
|
|
settings = Settings.from_env()
|
|
|
|
assert settings.max_likes == 5
|
|
assert settings.facebook_email == "a@b.c"
|