Selenium tests of logistration password reset
This commit is contained in:
@@ -191,6 +191,32 @@ class CombinedLoginAndRegisterPage(PageObject):
|
||||
# Submit it
|
||||
self.q(css=".login-button").click()
|
||||
|
||||
def password_reset(self, email):
|
||||
"""Navigates to, fills in, and submits the password reset form.
|
||||
|
||||
Requires that the "login" form is visible.
|
||||
|
||||
Keyword Arguments:
|
||||
email (unicode): The user's email address.
|
||||
|
||||
"""
|
||||
login_form = self.current_form
|
||||
|
||||
# Click the password reset link on the login page
|
||||
self.q(css="a.forgot-password").click()
|
||||
|
||||
# Wait for the password reset form to load
|
||||
EmptyPromise(
|
||||
lambda: self.current_form != login_form,
|
||||
"Finish toggling to the password reset form"
|
||||
).fulfill()
|
||||
|
||||
# Fill in the form
|
||||
self.q(css="#password-reset-email").fill(email)
|
||||
|
||||
# Submit it
|
||||
self.q(css="button.js-reset").click()
|
||||
|
||||
@property
|
||||
@unguarded
|
||||
def current_form(self):
|
||||
@@ -207,7 +233,7 @@ class CombinedLoginAndRegisterPage(PageObject):
|
||||
return "register"
|
||||
elif self.q(css=".login-button").visible:
|
||||
return "login"
|
||||
elif self.q(css=".js-reset").visible:
|
||||
elif self.q(css=".js-reset").visible or self.q(css=".js-reset-success").visible:
|
||||
return "password-reset"
|
||||
|
||||
@property
|
||||
@@ -221,3 +247,16 @@ class CombinedLoginAndRegisterPage(PageObject):
|
||||
errors = self.errors
|
||||
return (bool(errors), errors)
|
||||
return Promise(_check_func, "Errors are visible").fulfill()
|
||||
|
||||
@property
|
||||
def success(self):
|
||||
"""Return a success message displayed to the user."""
|
||||
if self.q(css=".submission-success").visible:
|
||||
return self.q(css=".submission-success h4").text
|
||||
|
||||
def wait_for_success(self):
|
||||
"""Wait for a success message to be visible, then return it."""
|
||||
def _check_func():
|
||||
success = self.success
|
||||
return (bool(success), success)
|
||||
return Promise(_check_func, "Success message is visible").fulfill()
|
||||
|
||||
@@ -69,7 +69,12 @@ class RegistrationTest(UniqueCourseTest):
|
||||
|
||||
@attr('shard_1')
|
||||
class LoginFromCombinedPageTest(UniqueCourseTest):
|
||||
"""Test that we can log in using the combined login/registration page. """
|
||||
"""Test that we can log in using the combined login/registration page.
|
||||
|
||||
Also test that we can request a password reset from the combined
|
||||
login/registration page.
|
||||
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
"""Initialize the page objects and create a test course. """
|
||||
@@ -112,6 +117,29 @@ class LoginFromCombinedPageTest(UniqueCourseTest):
|
||||
self.login_page.visit().toggle_form()
|
||||
self.assertEqual(self.login_page.current_form, "register")
|
||||
|
||||
def test_password_reset_success(self):
|
||||
# Create a user account
|
||||
email, password = self._create_unique_user()
|
||||
|
||||
# Navigate to the password reset form and try to submit it
|
||||
self.login_page.visit().password_reset(email=email)
|
||||
|
||||
# Expect that we're shown a success message
|
||||
self.assertIn("PASSWORD RESET EMAIL SENT", self.login_page.wait_for_success())
|
||||
|
||||
def test_password_reset_failure(self):
|
||||
# Navigate to the password reset form
|
||||
self.login_page.visit()
|
||||
|
||||
# User account does not exist
|
||||
self.login_page.password_reset(email="nobody@nowhere.com")
|
||||
|
||||
# Expect that we're shown a failure message
|
||||
self.assertIn(
|
||||
"No active user with the provided email address exists.",
|
||||
self.login_page.wait_for_errors()
|
||||
)
|
||||
|
||||
def _create_unique_user(self):
|
||||
username = "test_{uuid}".format(uuid=self.unique_id[0:6])
|
||||
email = "{user}@example.com".format(user=username)
|
||||
|
||||
Reference in New Issue
Block a user