def test_selenium_driver_driver_is_None():
    with patch(
            "league_history_collector.collectors.webdriver") as webdriver_mock:
        webdriver_mock.Remote.return_value = None

        with selenium_driver() as driver:
            assert driver is None
Пример #2
0
def run_collector(collector_config: NFLConfiguration):
    """Runs a collector on the league specified by the provided configuration."""

    with selenium_driver() as driver:
        collector = NFLCollector(collector_config, driver, (2, 4))
        league_data = collector.save_all_data()

        with open("league.json", "w") as outfile:
            outfile.write(league_data.to_json())
def test_selenium_driver_no_kwargs():
    with patch(
            "league_history_collector.collectors.webdriver") as webdriver_mock:
        driver_mock = MagicMock()
        webdriver_mock.Remote.return_value = driver_mock

        with selenium_driver() as driver:
            assert driver == driver_mock

        webdriver_mock.Remote.assert_called_once_with(
            command_executor="http://localhost:4444/wd/hub",
            desired_capabilities=DesiredCapabilities.CHROME,
        )
        driver_mock.close.assert_called_once()
def test_selenium_driver_with_kwargs():
    with patch(
            "league_history_collector.collectors.webdriver") as webdriver_mock:
        driver_mock = MagicMock()
        webdriver_mock.Remote.return_value = driver_mock

        command_executor = "command_executor"
        desired_capabilities = DesiredCapabilities.FIREFOX

        with selenium_driver(
                command_executor=command_executor,
                desired_capabilities=desired_capabilities) as driver:
            assert driver == driver_mock

        webdriver_mock.Remote.assert_called_once_with(
            command_executor=command_executor,
            desired_capabilities=desired_capabilities)
        driver_mock.close.assert_called_once()
    logger.add(sys.stderr, level="DEBUG")

    if FLAGS["SET_SEASON_DATA"] is True:
        for flag, value in FLAGS.items():
            if flag == "SET_SEASON_DATA":
                continue

            input(
                "SET_SEASON_DATA and at least one other flag are both True."
                "This may result in a longer than necessary test. Continue [Press ENTER]?"
            )
            break

    config = NFLConfiguration.load(filename="config.json")

    with selenium_driver() as driver:
        collector = NFLCollector(config, driver, (0, 1))
        collector._login()

        # These are required for some method calls, so always do this.
        team_to_manager, managers = collector._get_managers(2019)
        logger.info(f"Managers in 2019: {managers}")

        if FLAGS["GET_SEASONS"]:
            seasons = collector._get_seasons()
            logger.info(
                f"The following seasons are present in league history: {seasons}"
            )

        if FLAGS["GET_WEEKS"]:
            weeks = collector._get_weeks(2019)