<s> from __future__ import absolute_import , unicode_literals <EOL> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase , override_settings <EOL> from django . test . client import Client <EOL> from user_management . tests . literals import ( <EOL> TEST_ADMIN_EMAIL , TEST_ADMIN_PASSWORD , TEST_ADMIN_USERNAME <EOL> ) <EOL> from . literals import TEST_EMAIL_AUTHENTICATION_BACKEND <EOL> class UserLoginTestCase ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . admin_user = User . objects . create_superuser ( <EOL> username = TEST_ADMIN_USERNAME , email = TEST_ADMIN_EMAIL , <EOL> password = TEST_ADMIN_PASSWORD <EOL> ) <EOL> self . client = Client ( ) <EOL> @ override_settings ( AUTHENTICATION_LOGIN_METHOD = '<STR_LIT:username>' ) <EOL> def test_normal_behaviour ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( <EOL> response , '<STR_LIT>' <EOL> ) <EOL> @ override_settings ( AUTHENTICATION_LOGIN_METHOD = '<STR_LIT:username>' ) <EOL> def test_username_login ( self ) : <EOL> logged_in = self . client . login ( <EOL> username = TEST_ADMIN_USERNAME , password = TEST_ADMIN_PASSWORD <EOL> ) <EOL> self . assertTrue ( logged_in ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> @ override_settings ( AUTHENTICATION_LOGIN_METHOD = '<STR_LIT:email>' ) <EOL> def test_email_login ( self ) : <EOL> with self . settings ( AUTHENTICATION_BACKENDS = ( TEST_EMAIL_AUTHENTICATION_BACKEND , ) ) : <EOL> logged_in = self . client . login ( <EOL> username = TEST_ADMIN_USERNAME , password = TEST_ADMIN_PASSWORD <EOL> ) <EOL> self . assertFalse ( logged_in ) <EOL> logged_in = self . client . login ( <EOL> email = TEST_ADMIN_EMAIL , password = TEST_ADMIN_PASSWORD <EOL> ) <EOL> self . assertTrue ( logged_in ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> @ override_settings ( AUTHENTICATION_LOGIN_METHOD = '<STR_LIT:username>' ) <EOL> def test_username_login_via_views ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( <EOL> response , '<STR_LIT>' <EOL> ) <EOL> response = self . client . post ( <EOL> reverse ( settings . LOGIN_URL ) , { <EOL> '<STR_LIT:username>' : TEST_ADMIN_USERNAME , <EOL> '<STR_LIT:password>' : TEST_ADMIN_PASSWORD <EOL> } <EOL> ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> @ override_settings ( AUTHENTICATION_LOGIN_METHOD = '<STR_LIT:email>' ) <EOL> def test_email_login_via_views ( self ) : <EOL> with self . settings ( AUTHENTICATION_BACKENDS = ( TEST_EMAIL_AUTHENTICATION_BACKEND , ) ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( <EOL> response , '<STR_LIT>' <EOL> ) <EOL> response = self . client . post ( <EOL> reverse ( settings . LOGIN_URL ) , { <EOL> '<STR_LIT:email>' : TEST_ADMIN_EMAIL , '<STR_LIT:password>' : TEST_ADMIN_PASSWORD <EOL> } , follow = True <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) </s>
