<s> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase <EOL> from tos . compat import get_runtime_user_model <EOL> from tos . models import TermsOfService , UserAgreement , has_user_agreed_latest_tos <EOL> class TestViews ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . user1 = get_runtime_user_model ( ) . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . user2 = get_runtime_user_model ( ) . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . tos1 = TermsOfService . objects . create ( <EOL> content = "<STR_LIT>" , <EOL> active = True <EOL> ) <EOL> self . tos2 = TermsOfService . objects . create ( <EOL> content = "<STR_LIT>" , <EOL> active = False <EOL> ) <EOL> self . login_url = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> UserAgreement . objects . create ( <EOL> terms_of_service = self . tos1 , <EOL> user = self . user1 <EOL> ) <EOL> def test_login ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( has_user_agreed_latest_tos ( self . user1 ) ) <EOL> login = self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . failUnless ( login , '<STR_LIT>' ) <EOL> self . assertTrue ( has_user_agreed_latest_tos ( self . user1 ) ) <EOL> def test_need_agreement ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertFalse ( has_user_agreed_latest_tos ( self . user2 ) ) <EOL> response = self . client . post ( self . login_url , dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertFalse ( has_user_agreed_latest_tos ( self . user2 ) ) <EOL> def test_do_not_need_agreement ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertTrue ( has_user_agreed_latest_tos ( self . user1 ) ) <EOL> response = self . client . post ( self . login_url , dict ( username = '<STR_LIT>' , <EOL> password = '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> def test_redirect_security ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( self . login_url , dict ( username = '<STR_LIT>' , <EOL> password = '<STR_LIT>' , next = '<STR_LIT>' ) ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> self . assertIn ( settings . LOGIN_REDIRECT_URL , response . _headers [ '<STR_LIT:location>' ] [ <NUM_LIT:1> ] ) <EOL> def test_need_to_log_in ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( self . login_url ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_root_tos_view ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> def test_reject_agreement ( self ) : <EOL> self . assertFalse ( has_user_agreed_latest_tos ( self . user2 ) ) <EOL> response = self . client . post ( self . login_url , dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> response = self . client . post ( url , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertFalse ( has_user_agreed_latest_tos ( self . user2 ) ) <EOL> def test_accept_agreement ( self ) : <EOL> self . assertFalse ( has_user_agreed_latest_tos ( self . user2 ) ) <EOL> response = self . client . post ( self . login_url , dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertFalse ( has_user_agreed_latest_tos ( self . user2 ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> response = self . client . post ( url , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertTrue ( has_user_agreed_latest_tos ( self . user2 ) ) <EOL> def test_bump_new_agreement ( self ) : <EOL> self . tos2 . active = True <EOL> self . tos2 . save ( ) <EOL> self . assertFalse ( has_user_agreed_latest_tos ( self . user1 ) ) <EOL> response = self . client . post ( self . login_url , dict ( username = '<STR_LIT>' , password = '<STR_LIT>' ) ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertFalse ( has_user_agreed_latest_tos ( self . user2 ) ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> response = self . client . post ( url , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertTrue ( has_user_agreed_latest_tos ( self . user1 ) ) </s>
