Exemple #1
0
def test_comparison():
    """Test the comparison of `Post` objects."""
    post = Post(
        name="episode_01",
        submit_at=datetime(2018, 1, 6, 17, 0, 0),
        subreddit="anime",
        title="Slow Start - Episode 1 Discussion",
        body_template="*Slow Start*, Episode 1: The First Butterflies",
    )

    identical_post = Post(
        name="episode_01",
        submit_at=datetime(2018, 1, 6, 17, 0, 0),
        subreddit="anime",
        title="Slow Start - Episode 1 Discussion",
        body_template="*Slow Start*, Episode 1: The First Butterflies",
    )

    different_post = Post(
        name="episode_02",
        submit_at=datetime(2018, 1, 13, 12, 0, 0),
        subreddit="anime",
        title="Slow Start - Episode 2 Discussion",
        body_template="*Slow Start*, Episode 2: Exercise Wears Me Out ",
    )

    assert post == identical_post
    assert post != different_post
    assert post.__eq__("post") is NotImplemented  # noqa: WPS609
Exemple #2
0
def test_comparison(other_subreddit, other_post_ids, identical):
    """Test the comparison of `Post` objects."""
    posts = [
        Post(
            name="episode_{0}".format(post_id),
            submit_at=datetime(2018, 1, 6, 17, 0, 0),
            subreddit="anime",
            title="Slow Start - Episode {0} Discussion".format(post_id),
            body_template="*Slow Start*, Episode {0}".format(post_id),
        ) for post_id in range(1, 3)
    ]
    schedule = Schedule(subreddit="anime", posts=posts)

    other_posts = [
        Post(
            name="episode_{0}".format(post_id),
            submit_at=datetime(2018, 1, 6, 17, 0, 0),
            subreddit="anime",
            title="Slow Start - Episode {0} Discussion".format(post_id),
            body_template="*Slow Start*, Episode {0}".format(post_id),
        ) for post_id in other_post_ids
    ]
    other_schedule = Schedule(subreddit=other_subreddit, posts=other_posts)

    if identical:
        assert schedule == other_schedule
    else:
        assert schedule != other_schedule

    assert schedule.__eq__("schedule") is NotImplemented  # noqa: WPS609
Exemple #3
0
def test_create():
    """Test creating a `Post` instance."""
    post = Post(
        name="episode_01",
        submit_at=datetime(2018, 1, 6, 17, 0, 0),
        subreddit="anime",
        title="Slow Start - Episode 1 Discussion",
        body_template="*Slow Start*, Episode 1",
    )

    assert post.submit_at == datetime(2018, 1, 6, 17, 0, 0)
    assert post.subreddit == "anime"
    assert post.title == "Slow Start - Episode 1 Discussion"
    assert post.body_template == "*Slow Start*, Episode 1"

    assert (
        post.submit_with_thumbnail,
        post.flair_id,
        post.navigation_submitted,
        post.navigation_current,
        post.navigation_scheduled,
        post.submission_id,
        post.body_md,
        post.body_rtjson,
    ) == (
        True,  # Set to True by default
        None,
        "$link",  # Default value
        "",  # Default value
        "",  # Default value
        None,
        None,
        None,
    )
def test_build_navigation_links(
    mock_substitute_navigation_links,
    post_helper_config,
    reddit,
):
    """Test the preparation of the Navigation Links."""
    posts = [
        Post(
            name="e{0:02}".format(post),
            submit_at=datetime(2018, 1, 6, 17, 0, 0),
            subreddit="anime",
            title="Slow Start - Episode {0} Discussion".format(post),
            body_template="1:$e01|2:$e02|3:$e03",
            navigation_scheduled="-",
            navigation_submitted="$link",
            navigation_current="*",
        ) for post in range(1, 4)
    ]
    post_helper = PostHelper(post_helper_config, reddit)

    post_helper.build_navigation_links(posts[0], posts)
    assert mock_substitute_navigation_links.call_args == call(None, None)

    posts[0].submission_id = "id_1"
    post_helper.build_navigation_links(posts[1], posts)
    assert mock_substitute_navigation_links.call_args == call("id_1", None)

    posts[1].submission_id = "id_2"
    post_helper.build_navigation_links(posts[0], posts)
    assert mock_substitute_navigation_links.call_args == call(None, "id_2")

    posts[2].submission_id = "id_3"
    post_helper.build_navigation_links(posts[1], posts)
    assert mock_substitute_navigation_links.call_args == call("id_1", "id_3")
def post():
    """Return an example Post."""
    body_template = """*Slow Start*, Episode 1: The First Butterflies

---

**Streams:**

* [Crunchyroll](https://www.crunchyroll.com/slow-start/episode-1-the-first-butterflies-759027)
* [VRV](https://vrv.co/watch/G69P1KQ0Y/Slow-Start:The-First-Butterflies)

---

**Show Information:**

* [MyAnimeList](https://myanimelist.net/anime/35540)
* [AniDB](http://anidb.net/perl-bin/animedb.pl?show=anime&aid=13160)
* [AniList](https://anilist.co/anime/98693/SlowStart)
* [Official Website](http://slow-start.com)
* [US Website](http://slowstart-usa.com/)
* [Twitter](https://twitter.com/slosta_anime)
* [US Facebook Page](https://www.facebook.com/SlowStartUSA/)
"""  # noqa: E501

    return Post(
        name="episode_01",
        submit_at=datetime(2018, 1, 6, 17, 0, 0),
        subreddit="anime",
        title="Slow Start - Episode 1 Discussion",
        body_template=body_template,
        submit_with_thumbnail=True,
    )
Exemple #6
0
def test_create_with_empty_field():
    """Test that the `Post` cannot be instantiated with empty attributes."""
    with pytest.raises(AttributeError):
        Post(
            name="episode_01",
            submit_at=datetime(2018, 1, 6, 17, 0, 0),
            subreddit="anime",
            title="Slow Start - Episode 1 Discussion",
            body_template=None,  # type: ignore
        )
Exemple #7
0
def test_string_representation():
    """Test the string representation of a `Post` instance."""
    post = Post(
        name="episode_01",
        submit_at=datetime(2018, 1, 6, 17, 0, 0),
        subreddit="anime",
        title="Slow Start - Episode 1 Discussion",
        body_template="*Slow Start*, Episode 1: The First Butterflies",
    )

    assert "/r/anime Post at 2018-01-06 17:00:00: Slow Start" in str(post)
Exemple #8
0
def schedule():
    """Return the `Schedule` with 3 posts."""
    posts = [
        Post(
            name="episode_{0}".format(index + 1),
            submit_at=datetime(2018, 1, 6 + index * 7, 17, 0, 0),
            subreddit="anime",
            title="Slow Start - Episode {0} Discussion".format(index + 1),
            body_template="*Slow Start*, Episode {0}".format(index + 1),
        ) for index in range(0, 3)
    ]
    return Schedule(subreddit="anime", posts=posts)
Exemple #9
0
def test_create():
    """Test creating a `Post` instance."""
    posts = [
        Post(
            name="episode_{0}".format(post_id),
            submit_at=datetime(2018, 1, 6, 17, 0, 0),
            subreddit="anime",
            title="Slow Start - Episode {0} Discussion".format(post_id),
            body_template="*Slow Start*, Episode {0}".format(post_id),
        ) for post_id in range(1, 4)
    ]
    schedule = Schedule(subreddit="anime", posts=posts)

    assert schedule.subreddit == "anime"
    assert schedule.posts[0].subreddit == "anime"
    assert schedule.posts[1].title == "Slow Start - Episode 2 Discussion"
    assert schedule.posts[2].submit_with_thumbnail  # Set to True by default
def schedule():
    """
    Return mock `Schedule`.

    The first Post has `submission_id` filled in.
    """
    posts = [
        Post(
            name="episode_{0}".format(post_id),
            submit_at=datetime(2018, 1, 6, 17, 0, 0),
            subreddit="anime",
            title="Slow Start - Episode {0} Discussion".format(post_id),
            body_template="*Slow Start*, Episode {0}".format(post_id),
        ) for post_id in range(1, 4)
    ]
    posts[0].submission_id = "cute_id"

    return Schedule(subreddit="anime", posts=posts)
def test_prepare_post(
    mock_prepare_thumbnail,
    mock_build_navigation_links,
    post_helper_config,
    reddit,
):
    """
    Test the preparation of the post body.

    1. Prepare post without thumbnail.

    2. Prepare post with thumbnail.
    """
    mock_build_navigation_links.return_value = "links"
    posts = [
        Post(
            name="e{0:02}".format(post),
            submit_at=datetime(2018, 1, 6, 17, 0, 0),
            subreddit="anime",
            title="Slow Start - Episode {0} Discussion".format(post),
            body_template="$navigation_links|1:$e01|2:$e02|3:$e03",
            navigation_scheduled="-",
            navigation_submitted="$link",
            navigation_current="*",
        ) for post in range(1, 4)
    ]
    posts[0].submission_id = "cute_id"
    schedule = Schedule(subreddit="anime", posts=posts)

    post_helper = PostHelper(post_helper_config, reddit)

    post_helper.prepare_post(posts[1], schedule)

    assert posts[1].body_md == "links|1:/cute_id|2:*|3:-"
    assert posts[0].body_md is None
    assert mock_prepare_thumbnail.call_count == 0

    post_helper.prepare_post(posts[0], schedule, prepare_thumbnail=True)
    assert posts[0].body_md == "links|1:*|2:-|3:-"
    assert mock_prepare_thumbnail.call_count == 1
def test_update_posts(
    mock_reddit,
    mock_update_post,
    reddit_cutifier_config,
):
    """Test updating multiple posts."""
    posts = [
        Post(
            name="episode_{0}".format(post_id),
            submit_at=datetime(2018, 1, 6, 17, 0, 0),
            subreddit="anime",
            title="Slow Start - Episode {0} Discussion".format(post_id),
            body_template="*Slow Start*, Episode {0}".format(post_id),
        ) for post_id in range(1, 4)
    ]

    reddit_cutifier = RedditCutifier(reddit_cutifier_config)

    reddit_cutifier.update_posts(posts)

    expected_calls = [call(post) for post in posts]

    assert list(mock_update_post.call_args_list) == expected_calls