<s> from django . core . urlresolvers import reverse <EOL> from django . core import mail <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from webtest import AppError <EOL> from oscar . core . compat import get_user_model <EOL> from oscar . test . factories import UserFactory <EOL> from oscar . test . testcases import WebTestCase <EOL> User = get_user_model ( ) <EOL> class IndexViewTests ( WebTestCase ) : <EOL> is_staff = True <EOL> active_users_ids = [ ] <EOL> inactive_users_ids = [ ] <EOL> csrf_checks = False <EOL> def setUp ( self ) : <EOL> super ( IndexViewTests , self ) . setUp ( ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> UserFactory ( is_active = True ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT> ) : <EOL> UserFactory ( is_active = False ) <EOL> user_queryset = User . objects . all ( ) <EOL> self . active_users_ids = user_queryset . filter ( is_active = True ) . values_list ( '<STR_LIT:id>' , flat = True ) <EOL> self . inactive_users_ids = user_queryset . filter ( is_active = False ) . values_list ( '<STR_LIT:id>' , flat = True ) <EOL> def test_user_list_view ( self ) : <EOL> response = self . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertInContext ( response , '<STR_LIT>' ) <EOL> def test_make_active ( self ) : <EOL> params = { '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . inactive_users_ids } <EOL> response = self . post ( reverse ( '<STR_LIT>' ) , params = params ) <EOL> ex_inactive = User . objects . get ( id = self . inactive_users_ids [ <NUM_LIT:10> ] ) <EOL> self . assertIsRedirect ( response ) <EOL> self . assertTrue ( ex_inactive . is_active ) <EOL> def test_make_inactive ( self ) : <EOL> params = { '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . active_users_ids } <EOL> response = self . post ( reverse ( '<STR_LIT>' ) , params = params ) <EOL> ex_active = User . objects . get ( id = self . active_users_ids [ <NUM_LIT:10> ] ) <EOL> self . assertIsRedirect ( response ) <EOL> self . assertFalse ( ex_active . is_active ) <EOL> class DetailViewTests ( WebTestCase ) : <EOL> is_staff = True <EOL> def test_user_detail_view ( self ) : <EOL> response = self . get ( reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : <NUM_LIT:1> } ) ) <EOL> self . assertInContext ( response , '<STR_LIT:user>' ) <EOL> self . assertIsOk ( response ) <EOL> class TestDetailViewForStaffUser ( WebTestCase ) : <EOL> is_staff = True <EOL> def setUp ( self ) : <EOL> self . customer = UserFactory ( <EOL> username = '<STR_LIT>' , email = '<STR_LIT>' , password = '<STR_LIT:password>' ) <EOL> super ( TestDetailViewForStaffUser , self ) . setUp ( ) <EOL> def test_password_reset_url_only_available_via_post ( self ) : <EOL> try : <EOL> reset_url = reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . customer . id } <EOL> ) <EOL> self . get ( reset_url ) <EOL> except AppError as e : <EOL> self . assertIn ( '<STR_LIT>' , e . args [ <NUM_LIT:0> ] ) <EOL> def test_admin_can_reset_user_passwords ( self ) : <EOL> customer_page_url = reverse ( <EOL> '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . customer . id } <EOL> ) <EOL> customer_page = self . get ( customer_page_url ) <EOL> reset_form = customer_page . forms [ '<STR_LIT>' ] <EOL> response = reset_form . submit ( ) <EOL> self . assertRedirects ( response , customer_page_url ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> self . assertIn ( "<STR_LIT>" , mail . outbox [ <NUM_LIT:0> ] . subject ) <EOL> self . assertContains ( <EOL> response . follow ( ) , <EOL> _ ( "<STR_LIT>" ) <EOL> ) </s>
