<s> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase , Client <EOL> from django . contrib . auth . models import User <EOL> class TestloginPOST ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . c = Client ( ) <EOL> self . valid_data = { "<STR_LIT:username>" : "<STR_LIT:user>" , <EOL> "<STR_LIT:password>" : "<STR_LIT:password>" } <EOL> self . invalid_data = { "<STR_LIT:username>" : "<STR_LIT:none>" , <EOL> "<STR_LIT:password>" : "<STR_LIT:none>" } <EOL> User . objects . create_user ( ** self . valid_data ) <EOL> def test_valid_login ( self ) : <EOL> r = self . c . post ( reverse ( '<STR_LIT>' ) , data = self . valid_data , follow = True ) <EOL> self . assertRedirects ( r , reverse ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( self . c . login ( ** self . valid_data ) ) <EOL> def test_invalid_login ( self ) : <EOL> r = self . c . post ( reverse ( '<STR_LIT>' ) , data = self . invalid_data ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( r , "<STR_LIT>" ) <EOL> self . assertFalse ( self . c . login ( ** self . invalid_data ) ) <EOL> def test_disabled_account ( self ) : <EOL> u = User . objects . get ( username = self . valid_data [ '<STR_LIT:username>' ] ) <EOL> u . is_active = False <EOL> u . save ( ) <EOL> r = self . c . post ( reverse ( '<STR_LIT>' ) , data = self . valid_data ) <EOL> self . assertContains ( r , "<STR_LIT>" , status_code = <NUM_LIT:200> ) <EOL> def test_already_logged_in ( self ) : <EOL> self . c . post ( reverse ( '<STR_LIT>' ) , data = self . valid_data ) <EOL> r = self . c . post ( reverse ( '<STR_LIT>' ) , data = self . valid_data ) <EOL> self . assertContains ( r , '<STR_LIT>' ) <EOL> def test_login_redirect ( self ) : <EOL> redirect_data = { '<STR_LIT:username>' : self . valid_data [ '<STR_LIT:username>' ] , <EOL> '<STR_LIT:password>' : self . valid_data [ '<STR_LIT:password>' ] , <EOL> '<STR_LIT>' : reverse ( '<STR_LIT>' ) } <EOL> r = self . c . post ( reverse ( '<STR_LIT>' ) , data = redirect_data ) <EOL> self . assertRedirects ( r , reverse ( '<STR_LIT>' ) ) <EOL> def test_malformed_request ( self ) : <EOL> r = self . c . post ( reverse ( '<STR_LIT>' ) , data = { "<STR_LIT:a>" : "<STR_LIT:a>" , <NUM_LIT:1> : "<STR_LIT:b>" } ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) </s>
