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_notification_sent_on_new_topic(kind): p = UserFactory() u = UserFactory() f = ForumFactory(type=Forum.FORUM_POST) follow(user=u, obj=f) t = TopicFactory(forum=f, poster=p, type=kind) notification = Notification.objects.get() topic_string = format_html('<a href="{}">{}</a>', t.get_absolute_url(), t) if kind == Topic.TOPIC_ANNOUNCE: assert notification.print_notification(user=u).startswith( f"{user_profile_link(p)} announced {topic_string}") else: assert notification.print_notification( user=u).startswith(f"{user_profile_link(p)} posted {topic_string}")