Fix for duplicate email registration that meant flash error not being

displayed.

The error message does not specify the error is a duplicate email
address so as not to reveal which emails are current user accounts.
This commit is contained in:
Adam Shimali
2016-03-09 15:12:33 +00:00
parent eea5bfe749
commit 33c92a4e29
2 changed files with 36 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
from flask import url_for
from bs4 import BeautifulSoup
def test_render_register_returns_template_with_form(app_):
@@ -106,3 +107,24 @@ def test_should_return_400_if_password_is_blacklisted(app_,
response.status_code == 200
assert 'That password is blacklisted, too common' in response.get_data(as_text=True)
def test_register_with_existing_email_returns_error(app_,
api_user_active,
mock_get_user_by_email):
user_data = {
'name': 'Already Hasaccount',
'email_address': api_user_active.email_address,
'mobile_number': '+4407700900460',
'password': 'validPassword!'
}
with app_.test_request_context():
response = app_.test_client().post(url_for('main.register'),
data=user_data)
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
element = page.find('h1')
assert element.text == 'Create an account'
flash_banner = page.find('div', class_='banner-dangerous').string.strip()
assert flash_banner == 'There was an error registering your account'