<s> import datetime <EOL> from django . utils import timezone <EOL> from django . test import TestCase <EOL> from django . core . urlresolvers import reverse <EOL> from polls . models import Poll <EOL> def create_poll ( question , days ) : <EOL> """<STR_LIT>""" <EOL> return Poll . objects . create ( <EOL> question = question , <EOL> pub_date = timezone . now ( ) + datetime . timedelta ( days = days ) <EOL> ) <EOL> class PollViewTests ( TestCase ) : <EOL> def test_index_view_with_no_polls ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertQuerysetEqual ( response . context [ '<STR_LIT>' ] , [ ] ) <EOL> def test_index_view_with_a_past_poll ( self ) : <EOL> """<STR_LIT>""" <EOL> create_poll ( question = "<STR_LIT>" , days = - <NUM_LIT:30> ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertQuerysetEqual ( <EOL> response . context [ '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_index_view_with_a_future_poll ( self ) : <EOL> """<STR_LIT>""" <EOL> create_poll ( question = "<STR_LIT>" , days = <NUM_LIT:30> ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertContains ( <EOL> response , <EOL> "<STR_LIT>" , <EOL> status_code = <NUM_LIT:200> <EOL> ) <EOL> self . assertQuerysetEqual ( response . context [ '<STR_LIT>' ] , [ ] ) <EOL> def test_index_view_with_future_poll_and_past_poll ( self ) : <EOL> """<STR_LIT>""" <EOL> create_poll ( question = "<STR_LIT>" , days = - <NUM_LIT:30> ) <EOL> create_poll ( question = "<STR_LIT>" , days = <NUM_LIT:30> ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertQuerysetEqual ( <EOL> response . context [ '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_index_view_with_two_past_polls ( self ) : <EOL> """<STR_LIT>""" <EOL> create_poll ( question = "<STR_LIT>" , days = - <NUM_LIT:30> ) <EOL> create_poll ( question = "<STR_LIT>" , days = - <NUM_LIT:5> ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertQuerysetEqual ( <EOL> response . context [ '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> class PollIndexDetailTests ( TestCase ) : <EOL> def test_detail_view_with_a_future_poll ( self ) : <EOL> """<STR_LIT>""" <EOL> future_poll = create_poll ( question = '<STR_LIT>' , days = <NUM_LIT:5> ) <EOL> response = self . client . get ( <EOL> reverse ( '<STR_LIT>' , args = ( future_poll . id , ) ) <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_detail_view_with_a_past_poll ( self ) : <EOL> """<STR_LIT>""" <EOL> past_poll = create_poll ( question = '<STR_LIT>' , days = - <NUM_LIT:5> ) <EOL> response = self . client . get ( <EOL> reverse ( '<STR_LIT>' , args = ( past_poll . id , ) ) <EOL> ) <EOL> self . assertContains ( response , past_poll . question , status_code = <NUM_LIT:200> ) <EOL> class PollMethodTests ( TestCase ) : <EOL> def test_was_published_recently_with_future_poll ( self ) : <EOL> """<STR_LIT>""" <EOL> future_poll = Poll ( <EOL> pub_date = timezone . now ( ) + datetime . timedelta ( days = <NUM_LIT:30> ) <EOL> ) <EOL> self . assertEqual ( future_poll . was_published_recently ( ) , False ) <EOL> def test_was_published_recently_with_old_poll ( self ) : <EOL> """<STR_LIT>""" <EOL> old_poll = Poll ( pub_date = timezone . now ( ) - datetime . timedelta ( days = <NUM_LIT:30> ) ) <EOL> self . assertEqual ( old_poll . was_published_recently ( ) , False ) <EOL> def test_was_published_recently_with_recent_poll ( self ) : <EOL> """<STR_LIT>""" <EOL> recent_poll = Poll ( <EOL> pub_date = timezone . now ( ) - datetime . timedelta ( hours = <NUM_LIT:1> ) <EOL> ) <EOL> self . assertEqual ( recent_poll . was_published_recently ( ) , True ) </s>
