<s> from __future__ import unicode_literals <EOL> from django . core . urlresolvers import reverse <EOL> import pytest <EOL> from machina . apps . forum . signals import forum_viewed <EOL> from machina . core . db . models import get_model <EOL> from machina . core . loading import get_class <EOL> from machina . test . context_managers import mock_signal_receiver <EOL> from machina . test . factories import create_forum <EOL> from machina . test . factories import create_link_forum <EOL> from machina . test . testcases import BaseClientTestCase <EOL> Post = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> Topic = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> PermissionHandler = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assign_perm = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> remove_perm = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TestForumView ( BaseClientTestCase ) : <EOL> @ pytest . fixture ( autouse = True ) <EOL> def setup ( self ) : <EOL> self . perm_handler = PermissionHandler ( ) <EOL> self . top_level_forum = create_forum ( ) <EOL> self . top_level_link = create_link_forum ( link_redirects = True ) <EOL> assign_perm ( '<STR_LIT>' , self . user , self . top_level_forum ) <EOL> assign_perm ( '<STR_LIT>' , self . user , self . top_level_link ) <EOL> def test_browsing_works ( self ) : <EOL> correct_url = reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . top_level_forum . slug , '<STR_LIT>' : self . top_level_forum . id } ) <EOL> response = self . client . get ( correct_url , follow = True ) <EOL> assert response . status_code == <NUM_LIT:200> <EOL> def test_cannot_be_browsed_by_users_who_cannot_read_the_forum ( self ) : <EOL> remove_perm ( '<STR_LIT>' , self . user , self . top_level_forum ) <EOL> correct_url = reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . top_level_forum . slug , '<STR_LIT>' : self . top_level_forum . id } ) <EOL> response = self . client . get ( correct_url , follow = True ) <EOL> assert response . status_code == <NUM_LIT> <EOL> def test_triggers_a_viewed_signal ( self ) : <EOL> forum_url = reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . top_level_forum . slug , '<STR_LIT>' : self . top_level_forum . id } ) <EOL> link_url = reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . top_level_link . slug , '<STR_LIT>' : self . top_level_link . id } ) <EOL> for url in [ forum_url , link_url ] : <EOL> with mock_signal_receiver ( forum_viewed ) as receiver : <EOL> self . client . get ( url ) <EOL> assert receiver . call_count == <NUM_LIT:1> <EOL> def test_redirects_to_the_link_of_a_link_forum ( self ) : <EOL> correct_url = reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . top_level_link . slug , '<STR_LIT>' : self . top_level_link . id } ) <EOL> response = self . client . get ( correct_url ) <EOL> assert response . status_code == <NUM_LIT> <EOL> assert response [ '<STR_LIT>' ] == self . top_level_link . link <EOL> def test_increases_the_redirects_counter_of_a_link_forum ( self ) : <EOL> correct_url = reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . top_level_link . slug , '<STR_LIT>' : self . top_level_link . id } ) <EOL> initial_redirects_count = self . top_level_link . link_redirects_count <EOL> self . client . get ( correct_url ) <EOL> top_level_link = self . top_level_link . __class__ . _default_manager . get ( <EOL> pk = self . top_level_link . pk ) <EOL> assert top_level_link . link_redirects_count == initial_redirects_count + <NUM_LIT:1> </s>
