<s> from django . contrib . auth import SESSION_KEY <EOL> from django . test import Client , TestCase <EOL> from django . test . utils import override_settings <EOL> from mock import patch <EOL> from nopassword . models import LoginCode <EOL> from nopassword . utils import get_user_model <EOL> class TestViews ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . c = Client ( ) <EOL> self . user = get_user_model ( ) . objects . create ( username = '<STR_LIT:user>' ) <EOL> def tearDown ( self ) : <EOL> self . user . delete ( ) <EOL> def test_login ( self ) : <EOL> response = self . c . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> login = self . c . post ( '<STR_LIT>' , { '<STR_LIT:username>' : self . user . username } ) <EOL> self . assertEqual ( login . status_code , <NUM_LIT:200> ) <EOL> login_with_code = self . c . get ( '<STR_LIT>' % ( self . user . username , <EOL> '<STR_LIT>' ) ) <EOL> self . assertEqual ( login_with_code . status_code , <NUM_LIT> ) <EOL> login_url = '<STR_LIT>' % ( <EOL> self . user . username , <EOL> LoginCode . objects . all ( ) [ <NUM_LIT:0> ] . code <EOL> ) <EOL> login_with_code = self . c . get ( login_url ) <EOL> self . assertEqual ( login_with_code . status_code , <NUM_LIT:200> ) <EOL> login_post = self . c . post ( login_url ) <EOL> self . assertEqual ( login_post . status_code , <NUM_LIT> ) <EOL> self . assertIn ( SESSION_KEY , self . c . session ) <EOL> logout = self . c . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( logout . status_code , <NUM_LIT> ) <EOL> @ override_settings ( NOPASSWORD_POST_REDIRECT = False ) <EOL> def test_login_with_get ( self ) : <EOL> login = self . c . post ( '<STR_LIT>' , { '<STR_LIT:username>' : self . user . username } ) <EOL> self . assertEqual ( login . status_code , <NUM_LIT:200> ) <EOL> login_url = '<STR_LIT>' % ( <EOL> self . user . username , <EOL> LoginCode . objects . all ( ) [ <NUM_LIT:0> ] . code <EOL> ) <EOL> login_with_code = self . c . get ( login_url ) <EOL> self . assertEqual ( login_with_code . status_code , <NUM_LIT> ) <EOL> self . assertIn ( SESSION_KEY , self . c . session ) <EOL> @ override_settings ( NOPASSWORD_HIDE_USERNAME = True ) <EOL> def test_hide_username ( self ) : <EOL> response = self . c . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> login = self . c . post ( '<STR_LIT>' , { '<STR_LIT:username>' : self . user . username } ) <EOL> self . assertEqual ( login . status_code , <NUM_LIT:200> ) <EOL> login_with_code = self . c . get ( '<STR_LIT>' % '<STR_LIT>' ) <EOL> self . assertEqual ( login_with_code . status_code , <NUM_LIT> ) <EOL> code_url = '<STR_LIT>' % LoginCode . objects . all ( ) [ <NUM_LIT:0> ] . code <EOL> login_with_code = self . c . get ( code_url ) <EOL> self . assertEqual ( login_with_code . status_code , <NUM_LIT:200> ) <EOL> login_post = self . c . post ( code_url ) <EOL> self . assertEqual ( login_post . status_code , <NUM_LIT> ) <EOL> logout = self . c . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( logout . status_code , <NUM_LIT> ) <EOL> @ patch . object ( LoginCode , '<STR_LIT>' ) <EOL> def test_https_request ( self , mock_send_login_code ) : <EOL> login = self . c . post ( '<STR_LIT>' , <EOL> { '<STR_LIT:username>' : self . user . username } , <EOL> ** { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( login . status_code , <NUM_LIT:200> ) <EOL> mock_send_login_code . assert_called_with ( secure = True , host = '<STR_LIT>' ) <EOL> @ patch . object ( LoginCode , '<STR_LIT>' ) <EOL> def test_http_request ( self , mock_send_login_code ) : <EOL> login = self . c . post ( '<STR_LIT>' , <EOL> { '<STR_LIT:username>' : self . user . username } , <EOL> ** { '<STR_LIT>' : '<STR_LIT:http>' } ) <EOL> self . assertEqual ( login . status_code , <NUM_LIT:200> ) <EOL> mock_send_login_code . assert_called_with ( secure = False , host = '<STR_LIT>' ) </s>
