<s> from django . test import TestCase <EOL> from channels . models import Channel <EOL> from links . models import Link <EOL> from django . contrib . auth . models import User <EOL> from qhonuskan_votes . utils import get_vote_model <EOL> from datetime import datetime , timedelta <EOL> from links . utils import context_builder <EOL> from django . core . handlers . base import BaseHandler <EOL> from django . test . client import RequestFactory <EOL> class RequestMock ( RequestFactory ) : <EOL> def request ( self , ** request ) : <EOL> "<STR_LIT>" <EOL> request = RequestFactory . request ( self , ** request ) <EOL> handler = BaseHandler ( ) <EOL> handler . load_middleware ( ) <EOL> for middleware_method in handler . _request_middleware : <EOL> if middleware_method ( request ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return request <EOL> class ContextBuilderTest ( TestCase ) : <EOL> fixtures = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def setUp ( self ) : <EOL> self . users = User . objects . all ( ) <EOL> self . channels = Channel . objects . all ( ) <EOL> self . links = [ <EOL> Link . objects . create ( <EOL> posted_by = self . users [ <NUM_LIT:0> ] , <EOL> body = "<STR_LIT>" , <EOL> url = "<STR_LIT>" , <EOL> channel = self . channels [ <NUM_LIT:0> ] , <EOL> posted_at = datetime . now ( ) <EOL> ) , <EOL> Link . objects . create ( <EOL> posted_by = self . users [ <NUM_LIT:0> ] , <EOL> body = "<STR_LIT>" , <EOL> url = "<STR_LIT>" , <EOL> channel = Channel . objects . get ( pk = <NUM_LIT:1> ) , <EOL> posted_at = datetime . now ( ) - timedelta ( days = <NUM_LIT:1> ) <EOL> ) , <EOL> Link . objects . create ( <EOL> posted_by = self . users [ <NUM_LIT:0> ] , <EOL> body = "<STR_LIT>" , <EOL> url = "<STR_LIT>" , <EOL> channel = Channel . objects . get ( pk = <NUM_LIT:1> ) , <EOL> posted_at = datetime . now ( ) - timedelta ( days = <NUM_LIT:2> ) <EOL> ) <EOL> ] <EOL> def test_all_links ( self ) : <EOL> request = RequestMock ( ) . request ( ) <EOL> self . assertQuerysetEqual ( context_builder ( request ) [ '<STR_LIT>' ] , Link . objects . all ( ) ) </s>
