<s> from __future__ import unicode_literals <EOL> import pytest <EOL> from machina . core . db . models import get_model <EOL> from machina . test . factories import create_category_forum <EOL> from machina . test . factories import create_forum <EOL> from machina . test . factories import create_link_forum <EOL> from machina . test . factories import create_topic <EOL> from machina . test . factories import ForumReadTrackFactory <EOL> from machina . test . factories import PostFactory <EOL> from machina . test . factories import UserFactory <EOL> ForumReadTrack = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ pytest . mark . django_db <EOL> class TestForumReadTrackManager ( object ) : <EOL> @ pytest . fixture ( autouse = True ) <EOL> def setup ( self ) : <EOL> self . u1 = UserFactory . create ( ) <EOL> self . u2 = UserFactory . create ( ) <EOL> self . top_level_cat_1 = create_category_forum ( ) <EOL> self . top_level_cat_2 = create_category_forum ( ) <EOL> self . forum_1 = create_forum ( parent = self . top_level_cat_1 ) <EOL> self . forum_2 = create_forum ( parent = self . top_level_cat_1 ) <EOL> self . forum_2_child_1 = create_link_forum ( parent = self . forum_2 ) <EOL> self . forum_2_child_2 = create_forum ( parent = self . forum_2 ) <EOL> self . forum_3 = create_forum ( parent = self . top_level_cat_1 ) <EOL> self . forum_4 = create_forum ( parent = self . top_level_cat_2 ) <EOL> self . topic = create_topic ( forum = self . forum_2 , poster = self . u1 ) <EOL> PostFactory . create ( topic = self . topic , poster = self . u1 ) <EOL> ForumReadTrackFactory . create ( forum = self . forum_2 , user = self . u2 ) <EOL> def test_can_tell_if_a_forum_is_unread ( self ) : <EOL> PostFactory . create ( topic = self . topic , poster = self . u1 ) <EOL> unread_forums = ForumReadTrack . objects . get_unread_forums_from_list ( <EOL> self . top_level_cat_1 . get_descendants ( include_self = True ) , <EOL> self . u2 ) <EOL> assert self . forum_2 in unread_forums <EOL> def test_tells_that_the_ancestors_of_an_unread_forum_are_also_unread ( self ) : <EOL> PostFactory . create ( topic = self . topic , poster = self . u1 ) <EOL> unread_forums = ForumReadTrack . objects . get_unread_forums_from_list ( <EOL> self . top_level_cat_1 . get_descendants ( include_self = True ) , <EOL> self . u2 ) <EOL> assert set ( unread_forums ) == set ( [ <EOL> self . top_level_cat_1 , <EOL> self . forum_2 ] ) <EOL> def test_cannot_tell_that_the_descendant_of_an_unread_forum_are_also_unread ( self ) : <EOL> PostFactory . create ( topic = self . topic , poster = self . u1 ) <EOL> unread_forums = ForumReadTrack . objects . get_unread_forums_from_list ( <EOL> self . top_level_cat_1 . get_descendants ( include_self = True ) , <EOL> self . u2 ) <EOL> assert self . forum_2_child_2 not in unread_forums <EOL> def test_considers_a_forum_without_tracks_as_unread_if_it_has_topics ( self ) : <EOL> new_topic = create_topic ( forum = self . forum_2_child_2 , poster = self . u2 ) <EOL> PostFactory . create ( topic = new_topic , poster = self . u2 ) <EOL> unread_forums = ForumReadTrack . objects . get_unread_forums_from_list ( <EOL> self . top_level_cat_1 . get_descendants ( include_self = True ) , <EOL> self . u1 ) <EOL> assert self . forum_2_child_2 in unread_forums <EOL> def test_cannot_consider_a_forum_without_tracks_as_unread_if_it_has_only_unapproved_topics ( self ) : <EOL> new_topic = create_topic ( forum = self . forum_2_child_2 , poster = self . u2 ) <EOL> PostFactory . create ( topic = new_topic , poster = self . u2 , approved = False ) <EOL> unread_forums = ForumReadTrack . objects . get_unread_forums_from_list ( <EOL> self . top_level_cat_1 . get_descendants ( include_self = True ) , <EOL> self . u1 ) <EOL> assert self . forum_2_child_2 not in unread_forums </s>
