<s> from __future__ import unicode_literals <EOL> from django . contrib . sessions . middleware import SessionMiddleware <EOL> from django . template import Context <EOL> from django . template . base import Template <EOL> from django . template . loader import render_to_string <EOL> from django . test . client import RequestFactory <EOL> import pytest <EOL> from machina . apps . forum_permission . middleware import ForumPermissionMiddleware <EOL> from machina . core . db . models import get_model <EOL> from machina . core . loading import get_class <EOL> from machina . test . factories import create_category_forum <EOL> from machina . test . factories import create_forum <EOL> from machina . test . factories import create_topic <EOL> from machina . test . factories import PostFactory <EOL> from machina . test . factories import UserFactory <EOL> Forum = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <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> @ pytest . mark . django_db <EOL> class TestForumLastPostTag ( object ) : <EOL> @ pytest . fixture ( autouse = True ) <EOL> def setup ( self ) : <EOL> self . loadstatement = '<STR_LIT>' <EOL> self . user = UserFactory . create ( ) <EOL> self . perm_handler = PermissionHandler ( ) <EOL> self . top_level_cat = create_category_forum ( ) <EOL> self . forum_1 = create_forum ( parent = self . top_level_cat ) <EOL> self . forum_2 = create_forum ( parent = self . top_level_cat ) <EOL> self . forum_1_topic = create_topic ( forum = self . forum_1 , poster = self . user ) <EOL> self . forum_2_topic = create_topic ( forum = self . forum_2 , poster = self . user ) <EOL> self . post_1 = PostFactory . create ( topic = self . forum_1_topic , poster = self . user ) <EOL> self . post_2 = PostFactory . create ( topic = self . forum_2_topic , poster = self . user ) <EOL> assign_perm ( '<STR_LIT>' , self . user , self . top_level_cat ) <EOL> assign_perm ( '<STR_LIT>' , self . user , self . forum_1 ) <EOL> def test_can_provide_the_last_post_of_a_forum ( self ) : <EOL> t = Template ( self . loadstatement + '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT>' : self . forum_1 , '<STR_LIT:user>' : self . user } ) <EOL> rendered = t . render ( c ) <EOL> assert rendered == '<STR_LIT>' <EOL> assert c [ '<STR_LIT>' ] == self . post_1 <EOL> @ pytest . mark . django_db <EOL> class TestForumListTag ( object ) : <EOL> @ pytest . fixture ( autouse = True ) <EOL> def setup ( self ) : <EOL> self . loadstatement = '<STR_LIT>' <EOL> self . request_factory = RequestFactory ( ) <EOL> self . user = UserFactory . create ( ) <EOL> self . top_level_cat = create_category_forum ( ) <EOL> self . forum_1 = create_forum ( parent = self . top_level_cat ) <EOL> self . forum_2 = create_forum ( parent = self . top_level_cat ) <EOL> def test_can_render_a_list_of_forums_according_to_their_minimum_tree_level ( self ) : <EOL> forums = Forum . objects . all ( ) <EOL> request = self . request_factory . get ( '<STR_LIT:/>' ) <EOL> middleware = SessionMiddleware ( ) <EOL> middleware . process_request ( request ) <EOL> request . session . save ( ) <EOL> request . user = self . user <EOL> ForumPermissionMiddleware ( ) . process_request ( request ) <EOL> t = Template ( self . loadstatement + '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT>' : forums , '<STR_LIT>' : request } ) <EOL> expected_out = render_to_string ( <EOL> '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : forums , <EOL> '<STR_LIT:user>' : self . user , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> } <EOL> ) <EOL> rendered = t . render ( c ) <EOL> assert rendered != '<STR_LIT>' <EOL> assert rendered == expected_out </s>
