Ejemplo n.º 1
0
def test_follow_clean_up_after_post_removal():
    u = UserFactory()
    f = ForumFactory(type=Forum.FORUM_POST)
    t = TopicFactory(forum=f, type=Topic.TOPIC_POST)
    p1 = PostFactory(topic=t, poster=u)
    p2 = PostFactory(topic=t, poster=u)

    follow(u, p1)
    follow(u, p2)

    p1.delete()

    assert not is_following(u, p1)
Ejemplo n.º 2
0
def test_follow_if_post_in_topic():
    u = UserFactory()
    f = ForumFactory(type=Forum.FORUM_POST)
    t = TopicFactory(forum=f, type=Topic.TOPIC_POST)
    PostFactory(topic=t, poster=u)

    assert Follow.objects.is_following(user=u, instance=t)
Ejemplo n.º 3
0
def test_notification_sent_on_new_post(kind):
    u1 = UserFactory()
    u2 = UserFactory()
    f = ForumFactory(type=Forum.FORUM_POST)
    follow(user=u2, obj=f)
    t = TopicFactory(forum=f, poster=u1, type=kind)
    PostFactory(topic=t, poster=u2)

    notifications = Notification.objects.all()
    topic_string = format_html('<a href="{}">{}</a>', t.get_absolute_url(), t)
    forum_string = format_html('<a href="{}">{}</a>', f.get_absolute_url(), f)
    assert len(notifications) == 2
    assert (
        notifications[1]
        .print_notification(user=u1)
        .startswith(f"{user_profile_link(u2)} replied to {topic_string}")
    )

    if kind == Topic.TOPIC_ANNOUNCE:
        assert (
            notifications[0]
            .print_notification(user=u2)
            .startswith(
                f"{user_profile_link(t.poster)} announced {topic_string} in {forum_string}"
            )
        )
    else:
        assert (
            notifications[0]
            .print_notification(user=u2)
            .startswith(
                f"{user_profile_link(t.poster)} posted {topic_string} in {forum_string}"
            )
        )
def test_action_created_on_new_post(kind):
    u = UserFactory()
    f = ForumFactory(type=Forum.FORUM_POST)
    t = TopicFactory(forum=f, type=kind)
    PostFactory(topic=t, poster=u)

    actions = Action.objects.all()

    assert len(actions) == 2
    assert str(actions[0]).startswith(f"{u} replied to {t}")

    if kind == Topic.TOPIC_ANNOUNCE:
        assert str(actions[1]).startswith(f"{t.poster} announced {t} on {f}")
    else:
        assert str(actions[1]).startswith(f"{t.poster} posted {t} on {f}")