<s> import re <EOL> from django . core import mail <EOL> from django . core . urlresolvers import reverse <EOL> from django_webtest import WebTest <EOL> from oscar . test . testcases import WebTestCase <EOL> from oscar . test import factories <EOL> from oscar . core . compat import get_user_model <EOL> User = get_user_model ( ) <EOL> class TestAUserWhoseForgottenHerPassword ( WebTest ) : <EOL> def test_can_reset_her_password ( self ) : <EOL> username , email , password = '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:password>' <EOL> User . objects . create_user ( username , email , password ) <EOL> page = self . app . get ( reverse ( '<STR_LIT>' ) ) <EOL> form = page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT:email>' ] = email <EOL> response = form . submit ( ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( mail . outbox ) ) <EOL> email_body = mail . outbox [ <NUM_LIT:0> ] . body <EOL> urlfinder = re . compile ( r"<STR_LIT>" ) <EOL> matches = urlfinder . search ( email_body , re . MULTILINE ) <EOL> self . assertTrue ( '<STR_LIT:path>' in matches . groupdict ( ) ) <EOL> path = matches . groupdict ( ) [ '<STR_LIT:path>' ] <EOL> reset_page = self . app . get ( path ) <EOL> form = reset_page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> form [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> response = form . submit ( ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> form = self . app . get ( url ) . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = email <EOL> form [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> response = form . submit ( '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> class TestAnAuthenticatedUser ( WebTestCase ) : <EOL> is_anonymous = False <EOL> def test_receives_an_email_when_their_password_is_changed ( self ) : <EOL> page = self . get ( reverse ( '<STR_LIT>' ) ) <EOL> form = page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = self . password <EOL> form [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> form [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page = form . submit ( ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> self . assertIn ( "<STR_LIT>" , mail . outbox [ <NUM_LIT:0> ] . body ) <EOL> def test_cannot_access_reset_password_page ( self ) : <EOL> response = self . get ( reverse ( '<STR_LIT>' ) , status = <NUM_LIT> ) <EOL> self . assertEqual ( <NUM_LIT> , response . status_code ) <EOL> def test_does_not_receive_an_email_when_their_profile_is_updated_but_email_address_not_changed ( self ) : <EOL> page = self . get ( reverse ( '<STR_LIT>' ) ) <EOL> form = page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> form . submit ( ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:0> ) <EOL> def test_receives_an_email_when_their_email_address_is_changed ( self ) : <EOL> page = self . get ( reverse ( '<STR_LIT>' ) ) <EOL> form = page . forms [ '<STR_LIT>' ] <EOL> new_email = '<STR_LIT>' <EOL> form [ '<STR_LIT:email>' ] = new_email <EOL> page = form . submit ( ) <EOL> self . assertEqual ( len ( mail . outbox ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( mail . outbox [ <NUM_LIT:0> ] . to [ <NUM_LIT:0> ] , self . email ) <EOL> self . assertEqual ( User . objects . get ( id = self . user . id ) . email , new_email ) <EOL> self . assertIn ( "<STR_LIT>" , <EOL> mail . outbox [ <NUM_LIT:0> ] . body ) <EOL> class TestAnAnonymousUser ( WebTestCase ) : <EOL> is_anonymous = True <EOL> def assertCanLogin ( self , email , password ) : <EOL> url = reverse ( '<STR_LIT>' ) <EOL> form = self . app . get ( url ) . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = email <EOL> form [ '<STR_LIT>' ] = password <EOL> response = form . submit ( '<STR_LIT>' ) <EOL> self . assertRedirectsTo ( response , '<STR_LIT>' ) <EOL> def test_can_login ( self ) : <EOL> email , password = '<STR_LIT>' , '<STR_LIT>' <EOL> User . objects . create_user ( '<STR_LIT:_>' , email , password ) <EOL> self . assertCanLogin ( email , password ) <EOL> def test_can_login_with_email_containing_capitals_in_local_part ( self ) : <EOL> email , password = '<STR_LIT>' , '<STR_LIT>' <EOL> User . objects . create_user ( '<STR_LIT:_>' , email , password ) <EOL> self . assertCanLogin ( email , password ) <EOL> def test_can_login_with_email_containing_capitals_in_host ( self ) : <EOL> email , password = '<STR_LIT>' , '<STR_LIT>' <EOL> User . objects . create_user ( '<STR_LIT:_>' , email , password ) <EOL> self . assertCanLogin ( email , password ) <EOL> def test_can_register ( self ) : <EOL> url = reverse ( '<STR_LIT>' ) <EOL> form = self . app . get ( url ) . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT:email>' ] = '<STR_LIT>' <EOL> form [ '<STR_LIT>' ] = form [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> response = form . submit ( ) <EOL> self . assertRedirectsTo ( response , '<STR_LIT>' ) <EOL> def test_casing_of_local_part_of_email_is_preserved ( self ) : <EOL> url = reverse ( '<STR_LIT>' ) <EOL> form = self . app . get ( url ) . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT:email>' ] = '<STR_LIT>' <EOL> form [ '<STR_LIT>' ] = form [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> form . submit ( ) <EOL> user = User . objects . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( user . email , '<STR_LIT>' ) <EOL> class TestAStaffUser ( WebTestCase ) : <EOL> is_anonymous = True <EOL> password = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . staff = factories . UserFactory . create ( <EOL> password = self . password , is_staff = True ) <EOL> super ( TestAStaffUser , self ) . setUp ( ) <EOL> def test_gets_redirected_to_the_dashboard_when_they_login ( self ) : <EOL> page = self . get ( reverse ( '<STR_LIT>' ) ) <EOL> form = page . forms [ '<STR_LIT>' ] <EOL> form [ '<STR_LIT>' ] = self . staff . email <EOL> form [ '<STR_LIT>' ] = self . password <EOL> response = form . submit ( '<STR_LIT>' ) <EOL> self . assertRedirectsTo ( response , '<STR_LIT>' ) </s>
