Merge branch 'master' into error-handling

Conflicts:
	app/main/views/invites.py
This commit is contained in:
Rebecca Law
2016-03-10 15:03:21 +00:00
16 changed files with 219 additions and 80 deletions

View File

@@ -3,6 +3,8 @@ from flask import url_for
from bs4 import BeautifulSoup
import app
from app.notify_client.models import InvitedUser
from tests.conftest import sample_invite as create_sample_invite
from tests.conftest import mock_check_invite_token as mock_check_token_invite
@@ -34,6 +36,25 @@ def test_existing_user_accept_invite_calls_api_and_redirects_to_dashboard(app_,
assert response.location == expected_redirect_location
def test_existing_user_cant_accept_twice(app_,
mocker,
sample_invite):
sample_invite['status'] = 'accepted'
invite = InvitedUser(**sample_invite)
mocker.patch('app.invite_api_client.check_token', return_value=invite)
with app_.test_request_context():
with app_.test_client() as client:
response = client.get(url_for('main.accept_invite', token='thisisnotarealtoken'), follow_redirects=True)
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.h1.string.strip() == 'Sign in'
flash_banners = page.find_all('div', class_='banner-default')
assert len(flash_banners) == 2
assert flash_banners[0].text.strip() == 'You have already accepted this invitation'
def test_existing_signed_out_user_accept_invite_redirects_to_sign_in(app_,
service_one,
api_user_active,

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 == 400
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'

View File

@@ -54,8 +54,9 @@ def test_should_redirect_after_change_service_name(app_,
with app_.test_client() as client:
client.login(api_user_active)
service_id = 123
response = client.post(url_for(
'main.service_name_change', service_id=service_id))
response = client.post(
url_for('main.service_name_change', service_id=service_id),
data={'name': "new name"})
assert response.status_code == 302
settings_url = url_for(
@@ -64,6 +65,27 @@ def test_should_redirect_after_change_service_name(app_,
assert mock_get_service.called
def test_should_not_allow_duplicate_names(app_,
api_user_active,
mock_get_service,
mock_get_user,
mock_get_user_by_email,
mock_login,
mock_has_permissions,
mock_get_services):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
service_id = 123
response = client.post(
url_for('main.service_name_change', service_id=service_id),
data={'name': "service_one"})
assert response.status_code == 200
resp_data = response.get_data(as_text=True)
assert 'This service name is already in use' in resp_data
def test_should_show_service_name_confirmation(app_,
api_user_active,
mock_get_service,
@@ -112,6 +134,32 @@ def test_should_redirect_after_service_name_confirmation(app_,
assert mock_update_service.called
def test_should_raise_duplicate_name_handled(app_,
api_user_active,
mock_get_service,
mock_update_service_raise_httperror_duplicate_name,
mock_get_user,
mock_get_user_by_email,
mock_login,
mock_verify_password,
mock_has_permissions):
with app_.test_request_context():
with app_.test_client() as client:
client.login(api_user_active)
service_id = 123
service_new_name = 'New Name'
with client.session_transaction() as session:
session['service_name_change'] = service_new_name
response = client.post(url_for(
'main.service_name_change_confirm', service_id=service_id))
assert response.status_code == 302
name_change_url = url_for(
'main.service_name_change', service_id=service_id, _external=True)
resp_data = response.get_data(as_text=True)
assert name_change_url == response.location
def test_should_show_request_to_go_live(app_,
api_user_active,
mock_get_service,