Exemplo n.º 1
0
def text_post_converter_config():
    """Return mock Config for testing the `TextPostConverter`."""
    return MockConfig({
        "reddit": {
            "user_agent": "Slow Start Rewatch Client"
        },
        "post_image_mime_types": {
            "gif": "image/gif"
        },
    })
Exemplo n.º 2
0
def oauth_helper_config():
    """Return mock Config for testing OAuthHelper."""
    return MockConfig({
        "reddit": {"oauth_scope": ["headpat", "hug"]},
        "http_server": {
            "hostname": HTTP_SERVER_HOSTNAME,
            "port": HTTP_SERVER_PORT,
        },
        "refresh_token": None,
    })
Exemplo n.º 3
0
def test_load_schedule_data_error(tmpdir):
    """Test loading of the Schedule data from a nonexistent file."""
    schedule_path = tmpdir.join(SCHEDULE_FILENAME)
    config = MockConfig({"schedule_file": str(schedule_path)})

    schedule_file_storage = ScheduleFileStorage(config)

    assert not os.path.exists(schedule_path)

    with pytest.raises(MissingSchedule):
        schedule_file_storage.load_schedule_data()
Exemplo n.º 4
0
def schedule_file_storage_config(tmpdir):
    """Return mock Config contaning a path to a valid schedule."""
    schedule_path = tmpdir.join(SCHEDULE_FILENAME)
    with open(schedule_path, "w", encoding="utf-8") as schedule_file:
        schedule_file.write(SCHEDULE_DATA)

    post_body_path = tmpdir.join(POST_BODY_FILENAME)
    with open(post_body_path, "w", encoding="utf-8") as post_body_file:
        post_body_file.write(POST_BODY)

    return MockConfig({"schedule_file": str(schedule_path)})
def post_helper_config():
    """Return mock Config for testing the `PostHelper`."""
    return MockConfig({
        "reddit": {
            "user_agent": "Slow Start Rewatch Client"
        },
        "navigation_links": {
            "placeholder": "navigation_links",
            "template_empty": "",
            "template_previous": "$previous_link",
            "template_next": "$next_link",
            "template_both": "$previous_link$next_link",
        },
        "post_image_mime_types": "",
    })
Exemplo n.º 6
0
def test_load_post_body_error(tmpdir):
    """Test loading of the Post body from a file."""
    schedule_path = tmpdir.join(SCHEDULE_FILENAME)
    post_body_path = tmpdir.join(POST_BODY_FILENAME)
    config = MockConfig({"schedule_file": str(schedule_path)})

    schedule_file_storage = ScheduleFileStorage(config)

    assert not os.path.exists(post_body_path)

    with pytest.raises(MissingPost) as missing_post_error:
        schedule_file_storage.load_post_body(POST_BODY_FILENAME)

    # Comply with PT012: https://pypi.org/project/flake8-pytest-style/
    assert str(post_body_path) in str(missing_post_error.value)  # noqa: WPS441
Exemplo n.º 7
0
def test_save_schedule_data(tmpdir):
    """Test saving of the Schedule data to a file."""
    schedule_path = tmpdir.join(SCHEDULE_FILENAME)
    config = MockConfig({"schedule_file": str(schedule_path)})

    schedule_file_storage = ScheduleFileStorage(config)

    assert not os.path.exists(schedule_path)

    schedule_file_storage.save_schedule_data(SCHEDULE_DATA)

    with open(schedule_path, encoding="utf-8") as schedule_file:
        schedule_data = schedule_file.read()

    assert schedule_data == SCHEDULE_DATA
Exemplo n.º 8
0
def test_save_schedule_data_error(reddit_with_wiki):
    """Test saving of the Schedule data to the wiki with en error."""
    config = MockConfig({
        "schedule_wiki_url": "/r/anime/wiki/not-found",
    })

    schedule_wiki_storage = ScheduleWikiStorage(config, reddit_with_wiki)

    with pytest.raises(RedditError) as reddit_error:
        schedule_wiki_storage.save_schedule_data(SCHEDULE_DATA)

    # Comply with PT012: https://pypi.org/project/flake8-pytest-style/
    error_message = str(reddit_error.value)  # noqa: WPS441

    assert "Failed to update" in error_message
    assert "/r/anime/wiki/not-found" in error_message
Exemplo n.º 9
0
def test_load_post_body_not_found(reddit_with_wiki):
    """Test loading of the Post body from the nonexistent wiki."""
    config = MockConfig({
        "schedule_wiki_url": "/r/anime/wiki/not-found",
    })

    schedule_wiki_storage = ScheduleWikiStorage(config, reddit_with_wiki)

    with pytest.raises(MissingPost) as missing_post_error:
        schedule_wiki_storage.load_post_body("episode_01")

    # Comply with PT012: https://pypi.org/project/flake8-pytest-style/
    error_message = str(missing_post_error.value)  # noqa: WPS441

    assert "wiki page not found" in error_message
    assert "/r/anime/wiki/not-found/episode_01" in error_message
Exemplo n.º 10
0
def test_load_schedule_data_forbidden(reddit_with_wiki):
    """Test loading of the Schedule data from the inaccessible wiki."""
    config = MockConfig({
        "schedule_wiki_url": "/r/anime/wiki/forbidden",
    })

    schedule_wiki_storage = ScheduleWikiStorage(config, reddit_with_wiki)

    with pytest.raises(MissingSchedule) as missing_schedule_error:
        schedule_wiki_storage.load_schedule_data()

    # Comply with PT012: https://pypi.org/project/flake8-pytest-style/
    error_message = str(missing_schedule_error.value)  # noqa: WPS441

    assert "permissions to access" in error_message
    assert "/r/anime/wiki/forbidden" in error_message
def reddit_cutifier_config():
    """Return the mock `Config` for testing the `RedditCutifier`."""
    return MockConfig({
        "reddit": {
            "user_agent": REDDIT_USER_AGENT,
            "client_id": REDDIT_CLIENT_ID,
            "client_secret": REDDIT_CLIENT_SECRET,
        },
        "http_server": {
            "hostname": HTTP_SERVER_HOSTNAME,
            "port": HTTP_SERVER_PORT,
        },
        "reddit_cutifier": {
            "post_update_delay": 2000,
            "previous_post_update_delay": 2000,
        },
        "refresh_token": REFRESH_TOKEN,
    })
Exemplo n.º 12
0
def test_invalid_config(reddit_with_wiki):
    """Test initializing `ScheduleWikiStorage` with invalid config."""
    config = MockConfig({"schedule_wiki_url": None})

    with pytest.raises(RuntimeError):
        ScheduleWikiStorage(config, reddit_with_wiki)

    invalid_wiki_url = "/r/anime/slow-start-rewatch"

    config["schedule_wiki_url"] = invalid_wiki_url

    with pytest.raises(InvalidWikiLink) as invalid_wiki_link_error:
        ScheduleWikiStorage(config, reddit_with_wiki)

    # Comply with PT012: https://pypi.org/project/flake8-pytest-style/
    error_message = str(invalid_wiki_link_error.value)  # noqa: WPS441

    assert invalid_wiki_url in error_message
Exemplo n.º 13
0
def scheduler_config():
    """Return mock Config with the wiki storage configured."""
    return MockConfig({
        "schedule_wiki_url": "/r/anime/wiki/slow-start-rewatch",
        "schedule_file": None,
    })
Exemplo n.º 14
0
def schedule_wiki_storage_config(tmpdir):
    """Return mock Config contaning a wiki URL."""
    return MockConfig({
        "schedule_wiki_url": "/r/anime/wiki/slow-start-rewatch",
    })
def reddit_helper_config():
    """Return mock Config for testing the `RedditHelper`."""
    return MockConfig({"reddit": {"user_agent": "Slow Start Rewatch Client"}})
Exemplo n.º 16
0
def timer_config():
    """Return mock Config for testing the `Timer`."""
    return MockConfig({"timer": {"refresh_interval": 200}})
Exemplo n.º 17
0
def test_invalid_config():
    """Test initializing `ScheduleFileStorage` with invalid config."""
    config = MockConfig({"schedule_file": None})

    with pytest.raises(RuntimeError):
        ScheduleFileStorage(config)
Exemplo n.º 18
0
# -*- coding: utf-8 -*-

from unittest.mock import patch

import pytest

from slow_start_rewatch.app import App
from tests.conftest import MockConfig


@patch("slow_start_rewatch.app.Scheduler")
@patch("slow_start_rewatch.app.Timer")
@patch("slow_start_rewatch.app.RedditCutifier")
@patch("slow_start_rewatch.app.Config", return_value=MockConfig())
def test_init(
    mock_config,
    mock_reddit_cutifier,
    mock_timer,
    mock_scheduler,
):
    """Test that App parameters are stored to the Congig."""
    config = mock_config.return_value

    App()
    assert "schedule_wiki_url" not in config
    assert "schedule_file" not in config

    App(schedule_wiki_url="/r/anime/wiki/slow-start-rewatch")
    assert config["schedule_wiki_url"] == "/r/anime/wiki/slow-start-rewatch"

    App(schedule_file="schedule.yml")
Exemplo n.º 19
0
 def mock_get_config():
     from tests.conftest import MockConfig
     return MockConfig(False, "rhasspy_intent", "console", "rhasspy.json",
                       "german")