2020-09-13 21:39:44 +02:00
|
|
|
from .utils import (
|
|
|
|
TEST_URL,
|
|
|
|
random_string,
|
|
|
|
register,
|
2022-02-12 16:31:29 +01:00
|
|
|
register_valid_user_and_logout,
|
2020-09-13 21:39:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
URL = f'{TEST_URL}/register'
|
|
|
|
|
|
|
|
|
|
|
|
class TestRegistration:
|
|
|
|
def test_it_displays_registration_form(self, selenium):
|
|
|
|
selenium.get(URL)
|
|
|
|
selenium.implicitly_wait(1)
|
|
|
|
|
|
|
|
inputs = selenium.find_elements_by_tag_name('input')
|
2021-10-31 21:04:47 +01:00
|
|
|
assert len(inputs) == 4
|
|
|
|
assert inputs[0].get_attribute('id') == 'username'
|
2020-09-13 21:39:44 +02:00
|
|
|
assert inputs[0].get_attribute('type') == 'text'
|
2021-10-31 21:04:47 +01:00
|
|
|
assert inputs[1].get_attribute('id') == 'email'
|
2020-09-13 21:39:44 +02:00
|
|
|
assert inputs[1].get_attribute('type') == 'email'
|
2021-10-31 21:04:47 +01:00
|
|
|
assert inputs[2].get_attribute('id') == 'password'
|
2020-09-13 21:39:44 +02:00
|
|
|
assert inputs[2].get_attribute('type') == 'password'
|
2021-10-31 21:04:47 +01:00
|
|
|
|
2022-03-23 12:36:41 +01:00
|
|
|
form_infos = selenium.find_elements_by_class_name('form-info')
|
|
|
|
assert len(form_infos) == 3
|
|
|
|
assert form_infos[0].text == (
|
|
|
|
'3 to 30 characters required, only alphanumeric characters and '
|
|
|
|
'the underscore character "_" allowed.'
|
|
|
|
)
|
|
|
|
assert form_infos[1].text == 'Enter a valid email address.'
|
|
|
|
assert form_infos[2].text == 'At least 8 characters required.'
|
|
|
|
|
2021-10-31 21:04:47 +01:00
|
|
|
button = selenium.find_element_by_tag_name('button')
|
|
|
|
assert button.get_attribute('type') == 'submit'
|
|
|
|
assert 'Register' in button.text
|
2020-09-13 21:39:44 +02:00
|
|
|
|
2022-03-23 12:36:41 +01:00
|
|
|
links = selenium.find_elements_by_class_name('links')
|
|
|
|
assert links[0].tag_name == 'a'
|
|
|
|
assert 'Login' in links[0].text
|
|
|
|
assert links[1].tag_name == 'a'
|
|
|
|
assert "Didn't received instructions?" in links[1].text
|
2021-11-06 23:16:19 +01:00
|
|
|
|
2020-09-13 21:39:44 +02:00
|
|
|
def test_user_can_register(self, selenium):
|
2022-03-23 12:36:41 +01:00
|
|
|
user = {
|
|
|
|
'username': random_string(),
|
|
|
|
'email': f'{random_string()}@example.com',
|
|
|
|
'password': 'p@ssw0rd',
|
|
|
|
}
|
|
|
|
|
|
|
|
register(selenium, user)
|
2020-09-13 21:39:44 +02:00
|
|
|
|
2022-03-23 12:36:41 +01:00
|
|
|
message = selenium.find_element_by_class_name('success-message').text
|
|
|
|
assert (
|
|
|
|
'A link to activate your account has been '
|
|
|
|
'emailed to the address provided.'
|
|
|
|
) in message
|
2020-09-13 21:39:44 +02:00
|
|
|
|
|
|
|
def test_user_can_not_register_with_invalid_email(self, selenium):
|
|
|
|
user_name = random_string()
|
|
|
|
user_infos = {
|
|
|
|
'username': user_name,
|
|
|
|
'email': user_name,
|
|
|
|
'password': 'p@ssw0rd',
|
|
|
|
}
|
|
|
|
|
|
|
|
register(selenium, user_infos)
|
|
|
|
|
|
|
|
assert selenium.current_url == URL
|
2021-10-31 21:04:47 +01:00
|
|
|
nav = selenium.find_element_by_id('nav').text
|
2020-09-13 21:39:44 +02:00
|
|
|
assert 'Register' in nav
|
|
|
|
assert 'Login' in nav
|
|
|
|
|
|
|
|
def test_user_can_not_register_if_username_is_already_taken(
|
|
|
|
self, selenium
|
|
|
|
):
|
2022-02-12 16:31:29 +01:00
|
|
|
user = register_valid_user_and_logout(selenium)
|
|
|
|
user['email'] = f'{random_string()}@example.com'
|
2020-09-13 21:39:44 +02:00
|
|
|
|
2022-02-12 16:31:29 +01:00
|
|
|
register(selenium, user)
|
2020-09-13 21:39:44 +02:00
|
|
|
|
|
|
|
assert selenium.current_url == URL
|
2021-10-31 21:04:47 +01:00
|
|
|
errors = selenium.find_element_by_class_name('error-message').text
|
2022-03-23 12:36:41 +01:00
|
|
|
assert 'Sorry, that username is already taken.' in errors
|
2020-09-13 21:39:44 +02:00
|
|
|
|
2022-03-23 12:36:41 +01:00
|
|
|
def test_user_does_not_return_error_if_email_is_already_taken(
|
|
|
|
self, selenium
|
|
|
|
):
|
2022-02-12 16:31:29 +01:00
|
|
|
user = register_valid_user_and_logout(selenium)
|
|
|
|
user['username'] = random_string()
|
2020-09-13 21:39:44 +02:00
|
|
|
|
2022-02-12 16:31:29 +01:00
|
|
|
register(selenium, user)
|
2020-09-13 21:39:44 +02:00
|
|
|
|
2022-03-23 12:36:41 +01:00
|
|
|
assert selenium.current_url == f'{TEST_URL}/login'
|
|
|
|
message = selenium.find_element_by_class_name('success-message').text
|
|
|
|
assert (
|
|
|
|
'A link to activate your account has been '
|
|
|
|
'emailed to the address provided.'
|
|
|
|
) in message
|