def test_send_activation_mail(reahl_system_fixture, party_account_fixture): fixture = party_account_fixture system_account = fixture.new_system_account(email='*****@*****.**', activated=False) activation_request = VerifyEmailRequest( email=system_account.email, subject_config='accounts.activation_subject', email_config='accounts.activation_email') Session.add(activation_request) activation_action = ActivateAccount(system_account=system_account, requirements=[activation_request]) Session.add(activation_action) mailer_stub = fixture.mailer fixture.account_management_interface.email = system_account.email fixture.account_management_interface.password = system_account.password # Case: the first send fixture.account_management_interface.send_activation_notification() assert mailer_stub.mail_recipients == [system_account.email] assert mailer_stub.mail_sender == reahl_system_fixture.config.accounts.admin_email substitutions = { 'email': system_account.email, 'secret_key': activation_request.as_secret_key() } expected_subject = Template( reahl_system_fixture.config.accounts.activation_subject).substitute( substitutions) assert mailer_stub.mail_subject == expected_subject expected_message = Template( reahl_system_fixture.config.accounts.activation_email).substitute( substitutions) assert mailer_stub.mail_message == expected_message
def test_verify_from_menu(web_fixture, party_account_fixture, accounts_web_fixture): fixture = accounts_web_fixture account = party_account_fixture.new_system_account(activated=False) activation_request = VerifyEmailRequest( email=account.email, subject_config='accounts.activation_subject', email_config='accounts.activation_email') Session.add(activation_request) deferred_activation = ActivateAccount(system_account=account, requirements=[activation_request]) Session.add(deferred_activation) secret_key = activation_request.as_secret_key() assert not account.status.is_active() fixture.browser.open('/a_ui/verify') fixture.browser.type(XPath.input_labelled('Email'), account.email) fixture.browser.type(XPath.input_labelled('Secret key'), secret_key) fixture.browser.type(XPath.input_labelled('Password'), account.password) fixture.browser.click(XPath.button_labelled('Verify')) assert fixture.browser.current_url.path == '/a_ui/thanks' assert account.status.is_active()
def test_verify_from_menu(web_fixture, party_account_fixture, accounts_web_fixture): fixture = accounts_web_fixture account = party_account_fixture.new_system_account(activated=False) activation_request = VerifyEmailRequest( email=account.email, subject_config='accounts.activation_subject', email_config='accounts.activation_email') Session.add(activation_request) deferred_activation = ActivateAccount(system_account=account, requirements=[activation_request]) Session.add(deferred_activation) secret_key = activation_request.as_secret_key() assert not account.status.is_active() fixture.browser.open('/a_ui/verify') fixture.browser.type('//form[@id="verify"]//*[@name="verify-email"]', account.email) fixture.browser.type('//form[@id="verify"]//*[@name="verify-secret"]', secret_key) fixture.browser.type('//form[@id="verify"]//*[@name="verify-password"]', account.password) fixture.browser.click('//form[@id="verify"]//*[@value="Verify"]') assert fixture.browser.current_url.path == '/a_ui/thanks' assert account.status.is_active()
def test_register_help_pending(web_fixture, party_account_fixture, accounts_web_fixture): fixture = accounts_web_fixture verification_requests = Session.query(VerifyEmailRequest) unactivated_account = party_account_fixture.new_system_account( email='*****@*****.**', activated=False) activation_request = VerifyEmailRequest( email=unactivated_account.email, subject_config='accounts.activation_subject', email_config='accounts.activation_email') Session.add(activation_request) deferred_activation = ActivateAccount(system_account=unactivated_account, requirements=[activation_request]) Session.add(deferred_activation) fixture.browser.open('/a_ui/registerHelp') fixture.browser.type(XPath.input_labelled('Email'), unactivated_account.email) fixture.browser.click(XPath.button_labelled('Investigate')) assert fixture.browser.current_url.path == '/a_ui/registerHelp/pending' assert verification_requests.count() == 1 party_account_fixture.mailer.reset() fixture.browser.click(XPath.button_labelled('Send')) assert verification_requests.count() == 1 assert party_account_fixture.mailer.mail_sent assert fixture.browser.current_url.path == '/a_ui/registerHelp/pending/sent'
def activate_via_key(self, fixture): system_account = fixture.new_system_account(email='*****@*****.**', activated=False) activation_request = VerifyEmailRequest( email=system_account.email, subject_config='accounts.activation_subject', email_config='accounts.activation_email') Session.add(activation_request) deferred_activation = ActivateAccount( system_account=system_account, requirements=[activation_request]) Session.add(deferred_activation) account_management_interface = fixture.account_management_interface # Case where there is an email mismatch account_management_interface.email = '*****@*****.**' account_management_interface.secret = activation_request.as_secret_key( ) with expected(InvalidEmailException, test=lambda e: vassert(e.commit)): account_management_interface.verify_email() vassert(not system_account.registration_activated) # Case where there is a key mismatch account_management_interface.email = system_account.email account_management_interface.secret = 'a key that is invalid' with expected(KeyException): account_management_interface.verify_email() vassert(not system_account.registration_activated) # Case where it works vassert(not system_account.registration_activated) vassert(not system_account.account_enabled) vassert(not system_account.registration_date) account_management_interface.email = system_account.email account_management_interface.secret = activation_request.as_secret_key( ) account_management_interface.verify_email() vassert(system_account.registration_activated) vassert(system_account.account_enabled) assert_recent(system_account.registration_date) vassert( Session.query(VerifyEmailRequest).filter_by( id=activation_request.id).count() == 0)
def verify_from_menu(self, fixture): account = fixture.new_system_account(activated=False) activation_request = VerifyEmailRequest(email=account.email, subject_config='accounts.activation_subject', email_config='accounts.activation_email') Session.add(activation_request) deferred_activation = ActivateAccount(system_account=account, requirements=[activation_request]) Session.add(deferred_activation) secret_key = activation_request.as_secret_key() vassert( not account.status.is_active() ) fixture.browser.open('/a_ui/verify') fixture.browser.type('//form[@id="verify"]//*[@name="email"]', account.email) fixture.browser.type('//form[@id="verify"]//*[@name="secret"]', secret_key) fixture.browser.type('//form[@id="verify"]//*[@name="password"]', account.password) fixture.browser.click('//form[@id="verify"]//*[@value="Verify"]') vassert( fixture.browser.location_path == '/a_ui/thanks' ) vassert( account.status.is_active() )
def register_help_pending(self, fixture): verification_requests = Session.query(VerifyEmailRequest) unactivated_account = fixture.new_system_account(email='*****@*****.**', activated=False) activation_request = VerifyEmailRequest(email=unactivated_account.email, subject_config='accounts.activation_subject', email_config='accounts.activation_email') Session.add(activation_request) deferred_activation = ActivateAccount(system_account=unactivated_account, requirements=[activation_request]) Session.add(deferred_activation) fixture.browser.open('/a_ui/registerHelp') fixture.browser.type('//input[@name="email"]', unactivated_account.email) fixture.browser.click('//input[@value="Investigate"]') vassert( fixture.browser.location_path == '/a_ui/registerHelp/pending' ) vassert( verification_requests.count() == 1 ) fixture.mailer.reset() fixture.browser.click('//input[@value="Send"]') vassert( verification_requests.count() == 1 ) vassert( fixture.mailer.mail_sent ) vassert( fixture.browser.location_path == '/a_ui/registerHelp/pending/sent' )