Tests added for dao.

This commit is contained in:
Nicholas Staples
2016-01-15 15:15:35 +00:00
parent d42ee85f93
commit 3b1d521c10
39 changed files with 769 additions and 652 deletions

View File

@@ -2,9 +2,9 @@ from app.main.dao import verify_codes_dao, services_dao
from tests.app.main import create_test_user
def test_get_should_render_add_service_template(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_get_should_render_add_service_template(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
verify_codes_dao.add_code(user_id=user.id, code='12345', code_type='sms')
@@ -14,9 +14,9 @@ def test_get_should_render_add_service_template(notifications_admin, notificatio
assert 'Set up notifications for your service' in response.get_data(as_text=True)
def test_should_add_service_and_redirect_to_next_page(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_add_service_and_redirect_to_next_page(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
verify_codes_dao.add_code(user_id=user.id, code='12345', code_type='sms')
@@ -28,11 +28,11 @@ def test_should_add_service_and_redirect_to_next_page(notifications_admin, notif
assert saved_service is not None
def test_should_return_form_errors_when_service_name_is_empty(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_return_form_errors_when_service_name_is_empty(app_,
db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
verify_codes_dao.add_code(user_id=user.id, code='12345', code_type='sms')

View File

@@ -2,11 +2,11 @@ from tests.app.main import create_test_user
from flask import url_for
def test_should_show_choose_services_page(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_choose_services_page(app_,
db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services')

View File

@@ -3,14 +3,13 @@ from tests.app.main import create_test_user
from flask import url_for
def test_should_render_email_code_not_received_template_and_populate_email_address(notifications_admin,
notifications_admin_db,
notify_db_session,
mocker):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_render_email_code_not_received_template_and_populate_email_address(db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
_set_up_mocker(mocker)
user = create_test_user('pending')
session['user_email'] = user.email_address
response = client.get(url_for('main.check_and_resend_email_code'))
@@ -20,14 +19,13 @@ def test_should_render_email_code_not_received_template_and_populate_email_addre
assert 'value="test@user.gov.uk"' in response.get_data(as_text=True)
def test_should_check_and_resend_email_code_redirect_to_verify(notifications_admin,
notifications_admin_db,
notify_db_session,
mocker):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_check_and_resend_email_code_redirect_to_verify(db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
_set_up_mocker(mocker)
user = create_test_user('pending')
session['user_email'] = user.email_address
verify_codes_dao.add_code(user.id, code='12345', code_type='email')
@@ -37,12 +35,12 @@ def test_should_check_and_resend_email_code_redirect_to_verify(notifications_adm
assert response.location == url_for('main.verify', _external=True)
def test_should_render_text_code_not_received_template(notifications_admin,
notifications_admin_db,
notify_db_session,
mocker):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_render_text_code_not_received_template(db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
_set_up_mocker(mocker)
user = create_test_user('pending')
@@ -55,14 +53,13 @@ def test_should_render_text_code_not_received_template(notifications_admin,
assert 'value="+441234123412"'
def test_should_check_and_redirect_to_verify(notifications_admin,
notifications_admin_db,
notify_db_session,
mocker):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_check_and_redirect_to_verify(db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
_set_up_mocker(mocker)
user = create_test_user('pending')
session['user_email'] = user.email_address
verify_codes_dao.add_code(user.id, code='12345', code_type='sms')
@@ -72,14 +69,13 @@ def test_should_check_and_redirect_to_verify(notifications_admin,
assert response.location == url_for('main.verify', _external=True)
def test_should_update_email_address_resend_code(notifications_admin,
notifications_admin_db,
notify_db_session,
mocker):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_update_email_address_resend_code(db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
_set_up_mocker(mocker)
user = create_test_user('pending')
session['user_email'] = user.email_address
verify_codes_dao.add_code(user_id=user.id, code='12345', code_type='email')
@@ -91,14 +87,13 @@ def test_should_update_email_address_resend_code(notifications_admin,
assert updated_user.email_address == 'new@address.gov.uk'
def test_should_update_mobile_number_resend_code(notifications_admin,
notifications_admin_db,
notify_db_session,
mocker):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_update_mobile_number_resend_code(db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
_set_up_mocker(mocker)
user = create_test_user('pending')
session['user_email'] = user.email_address
verify_codes_dao.add_code(user_id=user.id, code='12345', code_type='sms')
@@ -110,11 +105,10 @@ def test_should_update_mobile_number_resend_code(notifications_admin,
assert updated_user.mobile_number == '+44 7700 900 460'
def test_should_render_verification_code_not_received(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_render_verification_code_not_received(db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
user = create_test_user('active')
session['user_email'] = user.email_address
@@ -125,32 +119,30 @@ def test_should_render_verification_code_not_received(notifications_admin,
'speak to your service manager to reset the number.' in response.get_data(as_text=True)
def test_check_and_redirect_to_two_factor(notifications_admin,
notifications_admin_db,
notify_db_session,
mocker):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_check_and_redirect_to_two_factor(db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
user = create_test_user('active')
session['user_email'] = user.email_address
_set_up_mocker(mocker)
response = client.get(url_for('main.check_and_resend_verification_code'))
assert response.status_code == 302
assert response.location == url_for('main.two_factor', _external=True)
def test_should_create_new_code_for_user(notifications_admin,
notifications_admin_db,
notify_db_session,
mocker):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_create_new_code_for_user(db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
user = create_test_user('active')
session['user_email'] = user.email_address
verify_codes_dao.add_code(user_id=user.id, code='12345', code_type='sms')
_set_up_mocker(mocker)
response = client.get(url_for('main.check_and_resend_verification_code'))
assert response.status_code == 302
assert response.location == url_for('main.two_factor', _external=True)
@@ -158,9 +150,3 @@ def test_should_create_new_code_for_user(notifications_admin,
assert len(codes) == 2
for x in ([used.code_used for used in codes]):
assert x is False
def _set_up_mocker(mocker):
# mocker.patch("app.admin_api_client.send_sms")
# mocker.patch("app.admin_api_client.send_email")
pass

View File

@@ -2,11 +2,11 @@ from tests.app.main import create_test_user
from flask import url_for
def test_should_show_recent_jobs_on_dashboard(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_recent_jobs_on_dashboard(app_,
db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/dashboard')

View File

@@ -3,24 +3,25 @@ from app.main.dao import users_dao
from tests.app.main import create_test_user
def test_should_render_forgot_password(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
response = notifications_admin.test_client().get(url_for('.forgot_password'))
def test_should_render_forgot_password(app_, db_, db_session):
with app_.test_request_context():
response = app_.test_client().get(url_for('.forgot_password'))
assert response.status_code == 200
assert 'If you have forgotten your password, we can send you an email to create a new password.' \
in response.get_data(as_text=True)
def test_should_redirect_to_password_reset_sent_and_state_updated(notifications_admin,
notifications_admin_db,
mocker,
notify_db_session):
# mocker.patch("app.admin_api_client.send_email")
with notifications_admin.test_request_context():
user = create_test_user('active')
response = notifications_admin.test_client().post(url_for('.forgot_password'),
data={'email_address': user.email_address})
def test_should_redirect_to_password_reset_sent_and_state_updated(app_,
db_,
db_session,
active_user,
mock_send_email):
with app_.test_request_context():
response = app_.test_client().post(
url_for('.forgot_password'),
data={'email_address': active_user.email_address})
assert response.status_code == 200
assert 'You have been sent an email containing a link to reset your password.' in response.get_data(
as_text=True)
assert users_dao.get_user_by_id(user.id).state == 'request_password_reset'
assert (
'You have been sent an email containing a link'
' to reset your password.') in response.get_data(as_text=True)
assert users_dao.get_user_by_id(active_user.id).state == 'request_password_reset'

View File

@@ -1,7 +1,7 @@
def test_owasp_useful_headers_set(notifications_admin):
with notifications_admin.test_request_context():
response = notifications_admin.test_client().get('/')
def test_owasp_useful_headers_set(app_):
with app_.test_request_context():
response = app_.test_client().get('/')
assert response.status_code == 200
assert response.headers['X-Frame-Options'] == 'deny'
assert response.headers['X-Content-Type-Options'] == 'nosniff'

View File

@@ -1,9 +1,9 @@
from tests.app.main import create_test_user
def test_should_return_list_of_all_jobs(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_return_list_of_all_jobs(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/jobs')
@@ -13,9 +13,9 @@ def test_should_return_list_of_all_jobs(notifications_admin, notifications_admin
assert 'Final reminder' in response.get_data(as_text=True)
def test_should_show_page_for_one_job(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_page_for_one_job(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
# TODO filename will be part of job metadata not in session
with client.session_transaction() as s:
s[456] = 'dispatch_20151114.csv'
@@ -28,9 +28,9 @@ def test_should_show_page_for_one_job(notifications_admin, notifications_admin_d
assert 'Test message 1' in response.get_data(as_text=True)
def test_should_show_page_for_one_notification(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_page_for_one_notification(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/jobs/456/notification/3')

View File

@@ -6,9 +6,9 @@ from app.notify_client.sender import generate_token
from tests.app.main import create_test_user
def test_should_render_new_password_template(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_render_new_password_template(db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('request_password_reset')
token = generate_token(user.email_address)
response = client.get(url_for('.new_password', token=token))
@@ -16,10 +16,9 @@ def test_should_render_new_password_template(notifications_admin, notifications_
assert ' You can now create a new password for your account.' in response.get_data(as_text=True)
def test_should_render_new_password_template_with_message_of_bad_token(notifications_admin, notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_render_new_password_template_with_message_of_bad_token(db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
create_test_user('request_password_reset')
token = generate_token('no_user@d.gov.uk')
response = client.get(url_for('.new_password', token=token))
@@ -28,13 +27,11 @@ def test_should_render_new_password_template_with_message_of_bad_token(notificat
response.get_data(as_text=True)
def test_should_redirect_to_two_factor_when_password_reset_is_successful(notifications_admin,
notifications_admin_db,
notify_db_session,
mocker):
_set_up_mocker(mocker)
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_redirect_to_two_factor_when_password_reset_is_successful(db_,
db_session,
mock_send_sms):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('request_password_reset')
token = generate_token(user.email_address)
response = client.post(url_for('.new_password', token=token), data={'new_password': 'a-new_password'})
@@ -45,32 +42,25 @@ def test_should_redirect_to_two_factor_when_password_reset_is_successful(notific
assert saved_user.state == 'active'
def test_should_redirect_to_forgot_password_with_flash_message_when_token_is_expired(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
notifications_admin.config['TOKEN_MAX_AGE_SECONDS'] = -1000
def test_should_redirect_to_forgot_password_with_flash_message_when_token_is_expired(db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
app_.config['TOKEN_MAX_AGE_SECONDS'] = -1000
user = create_test_user('request_password_reset')
token = generate_token(user.email_address)
response = client.post(url_for('.new_password', token=token), data={'new_password': 'a-new_password'})
assert response.status_code == 302
assert response.location == url_for('.forgot_password', _external=True)
notifications_admin.config['TOKEN_MAX_AGE_SECONDS'] = 3600
app_.config['TOKEN_MAX_AGE_SECONDS'] = 3600
def test_should_redirect_to_forgot_password_when_user_is_active_should_be_request_password_reset(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_redirect_to_forgot_password_when_user_is_active_should_be_request_password_reset(db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
token = generate_token(user.email_address)
response = client.post(url_for('.new_password', token=token), data={'new_password': 'a-new_password'})
assert response.status_code == 302
assert response.location == url_for('.index', _external=True)
def _set_up_mocker(mocker):
# mocker.patch("app.admin_api_client.send_sms")
pass

View File

@@ -1,57 +1,58 @@
from flask import url_for
def test_render_register_returns_template_with_form(notifications_admin, notifications_admin_db, notify_db_session):
response = notifications_admin.test_client().get('/register')
def test_render_register_returns_template_with_form(db_, db_session):
response = app_.test_client().get('/register')
assert response.status_code == 200
assert 'Create an account' in response.get_data(as_text=True)
def test_process_register_creates_new_user(notifications_admin, notifications_admin_db, mocker, notify_db_session):
_set_up_mocker(mocker)
response = notifications_admin.test_client().post('/register',
data={'name': 'Some One Valid',
'email_address': 'someone@example.gov.uk',
'mobile_number': '+4407700900460',
'password': 'validPassword!'})
def test_process_register_creates_new_user(db_,
db_session,
mock_send_sms,
mock_send_email):
response = app_.test_client().post('/register',
data={'name': 'Some One Valid',
'email_address': 'someone@example.gov.uk',
'mobile_number': '+4407700900460',
'password': 'validPassword!'})
assert response.status_code == 302
assert response.location == 'http://localhost/verify'
assert response.location == url_for('main.verify', _external=True)
def test_process_register_returns_400_when_mobile_number_is_invalid(notifications_admin,
notifications_admin_db,
mocker,
notify_db_session):
_set_up_mocker(mocker)
response = notifications_admin.test_client().post('/register',
data={'name': 'Bad Mobile',
'email_address': 'bad_mobile@example.gov.uk',
'mobile_number': 'not good',
'password': 'validPassword!'})
def test_process_register_returns_400_when_mobile_number_is_invalid(db_,
db_session,
mock_send_sms,
mock_send_email):
response = app_.test_client().post('/register',
data={'name': 'Bad Mobile',
'email_address': 'bad_mobile@example.gov.uk',
'mobile_number': 'not good',
'password': 'validPassword!'})
assert response.status_code == 200
assert 'Must be a UK mobile number (eg 07700 900460)' in response.get_data(as_text=True)
def test_should_return_400_when_email_is_not_gov_uk(notifications_admin,
notifications_admin_db,
mocker,
notify_db_session):
_set_up_mocker(mocker)
response = notifications_admin.test_client().post('/register',
data={'name': 'Bad Mobile',
'email_address': 'bad_mobile@example.not.right',
'mobile_number': '+44123412345',
'password': 'validPassword!'})
def test_should_return_400_when_email_is_not_gov_uk(db_,
db_session,
mock_send_sms,
mock_send_email):
response = app_.test_client().post('/register',
data={'name': 'Bad Mobile',
'email_address': 'bad_mobile@example.not.right',
'mobile_number': '+44123412345',
'password': 'validPassword!'})
assert response.status_code == 200
assert 'Enter a gov.uk email address' in response.get_data(as_text=True)
def test_should_add_verify_codes_on_session(notifications_admin, notifications_admin_db, mocker, notify_db_session):
_set_up_mocker(mocker)
with notifications_admin.test_client() as client:
def test_should_add_verify_codes_on_session(db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_client() as client:
response = client.post('/register',
data={'name': 'Test Codes',
'email_address': 'test_codes@example.gov.uk',
@@ -61,18 +62,12 @@ def test_should_add_verify_codes_on_session(notifications_admin, notifications_a
assert 'notify_admin_session' in response.headers.get('Set-Cookie')
def _set_up_mocker(mocker):
# mocker.patch("app.admin_api_client.send_sms")
# mocker.patch("app.admin_api_client.send_email")
pass
def test_should_return_400_if_password_is_blacklisted(notifications_admin, notifications_admin_db, notify_db_session):
response = notifications_admin.test_client().post('/register',
data={'name': 'Bad Mobile',
'email_address': 'bad_mobile@example.not.right',
'mobile_number': '+44123412345',
'password': 'password1234'})
def test_should_return_400_if_password_is_blacklisted(db_, db_session):
response = app_.test_client().post('/register',
data={'name': 'Bad Mobile',
'email_address': 'bad_mobile@example.not.right',
'mobile_number': '+44123412345',
'password': 'password1234'})
response.status_code == 200
assert 'That password is blacklisted, too common' in response.get_data(as_text=True)

View File

@@ -1,9 +1,9 @@
from tests.app.main import create_test_user
def test_should_show_overview(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_overview(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/service-settings')
@@ -11,9 +11,9 @@ def test_should_show_overview(notifications_admin, notifications_admin_db, notif
assert 'Service settings' in response.get_data(as_text=True)
def test_should_show_service_name(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_service_name(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/service-settings/name')
@@ -21,9 +21,9 @@ def test_should_show_service_name(notifications_admin, notifications_admin_db, n
assert 'Change your service name' in response.get_data(as_text=True)
def test_should_redirect_after_change_service_name(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_redirect_after_change_service_name(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.post('/services/123/service-settings/request-to-go-live')
@@ -32,9 +32,9 @@ def test_should_redirect_after_change_service_name(notifications_admin, notifica
assert 'http://localhost/services/123/service-settings' == response.location
def test_should_show_service_name_confirmation(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_service_name_confirmation(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/service-settings/name/confirm')
@@ -43,10 +43,10 @@ def test_should_show_service_name_confirmation(notifications_admin, notification
assert 'Change your service name' in response.get_data(as_text=True)
def test_should_redirect_after_service_name_confirmation(notifications_admin, notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_redirect_after_service_name_confirmation(app_, db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.post('/services/123/service-settings/name/confirm')
@@ -55,9 +55,9 @@ def test_should_redirect_after_service_name_confirmation(notifications_admin, no
assert 'http://localhost/services/123/service-settings' == response.location
def test_should_show_request_to_go_live(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_request_to_go_live(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/service-settings/request-to-go-live')
@@ -66,9 +66,9 @@ def test_should_show_request_to_go_live(notifications_admin, notifications_admin
assert 'Request to go live' in response.get_data(as_text=True)
def test_should_redirect_after_request_to_go_live(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_redirect_after_request_to_go_live(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.post('/services/123/service-settings/request-to-go-live')
@@ -77,9 +77,9 @@ def test_should_redirect_after_request_to_go_live(notifications_admin, notificat
assert 'http://localhost/services/123/service-settings' == response.location
def test_should_show_status_page(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_status_page(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/service-settings/status')
@@ -88,9 +88,9 @@ def test_should_show_status_page(notifications_admin, notifications_admin_db, no
assert 'Turn off all outgoing notifications' in response.get_data(as_text=True)
def test_should_show_redirect_after_status_change(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_redirect_after_status_change(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.post('/services/123/service-settings/status')
@@ -99,9 +99,9 @@ def test_should_show_redirect_after_status_change(notifications_admin, notificat
assert 'http://localhost/services/123/service-settings/status/confirm' == response.location
def test_should_show_status_confirmation(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_status_confirmation(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/service-settings/status/confirm')
@@ -110,9 +110,9 @@ def test_should_show_status_confirmation(notifications_admin, notifications_admi
assert 'Turn off all outgoing notifications' in response.get_data(as_text=True)
def test_should_redirect_after_status_confirmation(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_redirect_after_status_confirmation(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.post('/services/123/service-settings/status/confirm')
@@ -121,9 +121,9 @@ def test_should_redirect_after_status_confirmation(notifications_admin, notifica
assert 'http://localhost/services/123/service-settings' == response.location
def test_should_show_delete_page(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_delete_page(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/service-settings/delete')
@@ -132,9 +132,9 @@ def test_should_show_delete_page(notifications_admin, notifications_admin_db, no
assert 'Delete this service from Notify' in response.get_data(as_text=True)
def test_should_show_redirect_after_deleting_service(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_redirect_after_deleting_service(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.post('/services/123/service-settings/delete')
@@ -143,9 +143,9 @@ def test_should_show_redirect_after_deleting_service(notifications_admin, notifi
assert 'http://localhost/services/123/service-settings/delete/confirm' == response.location
def test_should_show_delete_confirmation(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_delete_confirmation(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/service-settings/delete/confirm')
@@ -154,9 +154,9 @@ def test_should_show_delete_confirmation(notifications_admin, notifications_admi
assert 'Delete this service from Notify' in response.get_data(as_text=True)
def test_should_redirect_delete_confirmation(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_redirect_delete_confirmation(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.post('/services/123/service-settings/delete/confirm')

View File

@@ -5,9 +5,9 @@ from app.models import User
from flask import url_for
def test_render_sign_in_returns_sign_in_template(notifications_admin):
with notifications_admin.test_request_context():
response = notifications_admin.test_client().get(url_for('main.sign_in'))
def test_render_sign_in_returns_sign_in_template(app_):
with app_.test_request_context():
response = app_.test_client().get(url_for('main.sign_in'))
assert response.status_code == 200
assert 'Sign in' in response.get_data(as_text=True)
assert 'Email address' in response.get_data(as_text=True)
@@ -15,8 +15,11 @@ def test_render_sign_in_returns_sign_in_template(notifications_admin):
assert 'Forgotten password?' in response.get_data(as_text=True)
def test_process_sign_in_return_2fa_template(notifications_admin, notifications_admin_db, mocker, notify_db_session):
_set_up_mocker(mocker)
def test_process_sign_in_return_2fa_template(app_,
db_,
db_session,
mock_send_sms,
mock_send_email):
user = User(email_address='valid@example.gov.uk',
password='val1dPassw0rd!',
mobile_number='+441234123123',
@@ -25,8 +28,8 @@ def test_process_sign_in_return_2fa_template(notifications_admin, notifications_
role_id=1,
state='active')
users_dao.insert_user(user)
with notifications_admin.test_request_context():
response = notifications_admin.test_client().post(
with app_.test_request_context():
response = app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'valid@example.gov.uk',
'password': 'val1dPassw0rd!'})
@@ -34,9 +37,9 @@ def test_process_sign_in_return_2fa_template(notifications_admin, notifications_
assert response.location == 'http://localhost/two-factor'
def test_should_return_locked_out_true_when_user_is_locked(notifications_admin,
notifications_admin_db,
notify_db_session):
def test_should_return_locked_out_true_when_user_is_locked(app_,
db_,
db_session):
user = User(email_address='valid@example.gov.uk',
password='val1dPassw0rd!',
mobile_number='+441234123123',
@@ -45,14 +48,14 @@ def test_should_return_locked_out_true_when_user_is_locked(notifications_admin,
role_id=1,
state='active')
users_dao.insert_user(user)
with notifications_admin.test_request_context():
with app_.test_request_context():
for _ in range(10):
notifications_admin.test_client().post(
app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'valid@example.gov.uk',
'password': 'whatIsMyPassword!'})
response = notifications_admin.test_client().post(
response = app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'valid@example.gov.uk',
'password': 'val1dPassw0rd!'})
@@ -60,7 +63,7 @@ def test_should_return_locked_out_true_when_user_is_locked(notifications_admin,
assert response.status_code == 200
assert 'Username or password is incorrect' in response.get_data(as_text=True)
another_bad_attempt = notifications_admin.test_client().post(
another_bad_attempt = app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'valid@example.gov.uk',
'password': 'whatIsMyPassword!'})
@@ -68,9 +71,9 @@ def test_should_return_locked_out_true_when_user_is_locked(notifications_admin,
assert 'Username or password is incorrect' in response.get_data(as_text=True)
def test_should_return_active_user_is_false_if_user_is_inactive(notifications_admin,
notifications_admin_db,
notify_db_session):
def test_should_return_active_user_is_false_if_user_is_inactive(app_,
db_,
db_session):
user = User(email_address='inactive_user@example.gov.uk',
password='val1dPassw0rd!',
mobile_number='+441234123123',
@@ -80,8 +83,8 @@ def test_should_return_active_user_is_false_if_user_is_inactive(notifications_ad
state='inactive')
users_dao.insert_user(user)
with notifications_admin.test_request_context():
response = notifications_admin.test_client().post(
with app_.test_request_context():
response = app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'inactive_user@example.gov.uk',
'password': 'val1dPassw0rd!'})
@@ -90,9 +93,9 @@ def test_should_return_active_user_is_false_if_user_is_inactive(notifications_ad
assert 'Username or password is incorrect' in response.get_data(as_text=True)
def test_should_return_200_when_user_does_not_exist(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
response = notifications_admin.test_client().post(
def test_should_return_200_when_user_does_not_exist(app_, db_, db_session):
with app_.test_request_context():
response = app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'does_not_exist@gov.uk',
'password': 'doesNotExist!'})
@@ -100,7 +103,7 @@ def test_should_return_200_when_user_does_not_exist(notifications_admin, notific
assert 'Username or password is incorrect' in response.get_data(as_text=True)
def test_should_return_200_when_user_is_not_active(notifications_admin, notifications_admin_db, notify_db_session):
def test_should_return_200_when_user_is_not_active(app_, db_, db_session):
user = User(email_address='PendingUser@example.gov.uk',
password='val1dPassw0rd!',
mobile_number='+441234123123',
@@ -109,16 +112,10 @@ def test_should_return_200_when_user_is_not_active(notifications_admin, notifica
role_id=1,
state='pending')
users_dao.insert_user(user)
with notifications_admin.test_request_context():
response = notifications_admin.test_client().post(
with app_.test_request_context():
response = app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'PendingUser@example.gov.uk',
'password': 'val1dPassw0rd!'})
assert response.status_code == 200
assert 'Username or password is incorrect' in response.get_data(as_text=True)
def _set_up_mocker(mocker):
# mocker.patch("app.admin_api_client.send_sms")
# mocker.patch("app.admin_api_client.send_email")
pass

View File

@@ -6,21 +6,21 @@ from app.models import User
from .test_sign_in import _set_up_mocker
def test_render_sign_out_redirects_to_sign_in(notifications_admin):
with notifications_admin.test_request_context():
response = notifications_admin.test_client().get(
def test_render_sign_out_redirects_to_sign_in(app_):
with app_.test_request_context():
response = app_.test_client().get(
url_for('main.sign_out'))
assert response.status_code == 302
assert response.location == url_for(
'main.sign_in', _external=True, next=url_for('main.sign_out'))
def test_sign_out_user(notifications_admin,
notifications_admin_db,
notify_db_session,
mocker):
with notifications_admin.test_request_context():
_set_up_mocker(mocker)
def test_sign_out_user(app_,
db_,
db_session,
mock_send_sms,
mock_send_email):
with app_.test_request_context():
email = 'valid@example.gov.uk'
password = 'val1dPassw0rd!'
user = User(email_address=email,
@@ -31,7 +31,7 @@ def test_sign_out_user(notifications_admin,
role_id=1,
state='active')
users_dao.insert_user(user)
with notifications_admin.test_client() as client:
with app_.test_client() as client:
client.login(user)
# Check we are logged in
response = client.get('/services/123/dashboard')

View File

@@ -6,12 +6,12 @@ from tests.app.main import create_test_user
def test_upload_empty_csvfile_returns_to_upload_page(
notifications_admin, notifications_admin_db, notify_db_session,
app_, db_, db_session,
mocker):
_setup_mocker_for_empty_file(mocker)
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
upload_data = {'file': (BytesIO(''.encode('utf-8')), 'emtpy.csv')}
@@ -24,7 +24,7 @@ def test_upload_empty_csvfile_returns_to_upload_page(
def test_upload_csvfile_with_invalid_phone_shows_check_page_with_errors(
notifications_admin, notifications_admin_db, notify_db_session,
app_, db_, db_session,
mocker):
contents = 'phone\n+44 123\n+44 456'
@@ -32,8 +32,8 @@ def test_upload_csvfile_with_invalid_phone_shows_check_page_with_errors(
m_open = mock_open(read_data=contents)
_setup_mocker_for_nonemtpy_file(mocker)
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
upload_data = {'file': file_data}
@@ -52,7 +52,7 @@ def test_upload_csvfile_with_invalid_phone_shows_check_page_with_errors(
def test_upload_csvfile_with_valid_phone_shows_first3_and_last3_numbers(
notifications_admin, notifications_admin_db, notify_db_session,
app_, db_, db_session,
mocker):
contents = 'phone\n+44 7700 900981\n+44 7700 900982\n+44 7700 900983\n+44 7700 900984\n+44 7700 900985\n+44 7700 900986\n+44 7700 900987\n+44 7700 900988\n+44 7700 900989' # noqa
@@ -61,8 +61,8 @@ def test_upload_csvfile_with_valid_phone_shows_first3_and_last3_numbers(
m_open = mock_open(read_data=contents)
_setup_mocker_for_nonemtpy_file(mocker)
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
upload_data = {'file': file_data}
@@ -89,7 +89,7 @@ def test_upload_csvfile_with_valid_phone_shows_first3_and_last3_numbers(
def test_upload_csvfile_with_valid_phone_shows_all_if_6_or_less_numbers(
notifications_admin, notifications_admin_db, notify_db_session,
app_, db_, db_session,
mocker):
contents = 'phone\n+44 7700 900981\n+44 7700 900982\n+44 7700 900983\n+44 7700 900984\n+44 7700 900985\n+44 7700 900986' # noqa
@@ -98,8 +98,8 @@ def test_upload_csvfile_with_valid_phone_shows_all_if_6_or_less_numbers(
m_open = mock_open(read_data=contents)
_setup_mocker_for_nonemtpy_file(mocker)
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
upload_data = {'file': file_data}
@@ -121,11 +121,11 @@ def test_upload_csvfile_with_valid_phone_shows_all_if_6_or_less_numbers(
assert '+44 7700 900986' in content
def test_should_redirect_to_job(notifications_admin, notifications_admin_db,
notify_db_session, mocker):
def test_should_redirect_to_job(app_, db_,
db_session, mocker):
_setup_mocker_for_check(mocker)
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
with client.session_transaction() as s:

View File

@@ -1,4 +1,4 @@
def test_styleguide_can_render(notifications_admin):
response = notifications_admin.test_client().get('/_styleguide')
def test_styleguide_can_render(app_):
response = app_.test_client().get('/_styleguide')
assert response.status_code == 200

View File

@@ -1,9 +1,9 @@
from tests.app.main import create_test_user
def test_should_return_list_of_all_templates(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_return_list_of_all_templates(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/templates')
@@ -11,9 +11,9 @@ def test_should_return_list_of_all_templates(notifications_admin, notifications_
assert response.status_code == 200
def test_should_show_page_for_one_templates(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_show_page_for_one_templates(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.get('/services/123/templates/template')
@@ -21,9 +21,9 @@ def test_should_show_page_for_one_templates(notifications_admin, notifications_a
assert response.status_code == 200
def test_should_redirect_when_saving_a_template(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_redirect_when_saving_a_template(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
user = create_test_user('active')
client.login(user)
response = client.post('/services/123/templates/template')

View File

@@ -4,9 +4,9 @@ from app.main.dao import verify_codes_dao
from tests.app.main import create_test_user
def test_should_render_two_factor_page(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_render_two_factor_page(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
# TODO this lives here until we work out how to
# reassign the session after it is lost mid register process
with client.session_transaction() as session:
@@ -17,9 +17,9 @@ def test_should_render_two_factor_page(notifications_admin, notifications_admin_
assert '''We've sent you a text message with a verification code.''' in response.get_data(as_text=True)
def test_should_login_user_and_redirect_to_dashboard(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_login_user_and_redirect_to_dashboard(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
user = create_test_user('active')
session['user_email'] = user.email_address
@@ -31,11 +31,11 @@ def test_should_login_user_and_redirect_to_dashboard(notifications_admin, notifi
assert response.location == url_for('main.choose_service', _external=True)
def test_should_return_200_with_sms_code_error_when_sms_code_is_wrong(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_return_200_with_sms_code_error_when_sms_code_is_wrong(app_,
db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
user = create_test_user('active')
session['user_email'] = user.email_address
@@ -46,11 +46,11 @@ def test_should_return_200_with_sms_code_error_when_sms_code_is_wrong(notificati
assert 'Code does not match' in response.get_data(as_text=True)
def test_should_login_user_when_multiple_valid_codes_exist(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_login_user_when_multiple_valid_codes_exist(app_,
db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
user = create_test_user('active')
session['user_email'] = user.email_address

View File

@@ -1,121 +1,121 @@
def test_should_show_overview_page(notifications_admin):
response = notifications_admin.test_client().get('/user-profile')
def test_should_show_overview_page(app_):
response = app_.test_client().get('/user-profile')
assert 'Your profile' in response.get_data(as_text=True)
assert response.status_code == 200
def test_should_show_name_page(notifications_admin):
response = notifications_admin.test_client().get('/user-profile/name')
def test_should_show_name_page(app_):
response = app_.test_client().get('/user-profile/name')
assert 'Change your name' in response.get_data(as_text=True)
assert response.status_code == 200
def test_should_redirect_after_name_change(notifications_admin):
response = notifications_admin.test_client().post('/user-profile/name')
def test_should_redirect_after_name_change(app_):
response = app_.test_client().post('/user-profile/name')
assert response.status_code == 302
assert response.location == 'http://localhost/user-profile'
def test_should_show_email_page(notifications_admin):
response = notifications_admin.test_client().get('/user-profile/email')
def test_should_show_email_page(app_):
response = app_.test_client().get('/user-profile/email')
assert 'Change your email address' in response.get_data(as_text=True)
assert response.status_code == 200
def test_should_redirect_after_email_change(notifications_admin):
response = notifications_admin.test_client().post('/user-profile/email')
def test_should_redirect_after_email_change(app_):
response = app_.test_client().post('/user-profile/email')
assert response.status_code == 302
assert response.location == 'http://localhost/user-profile/email/authenticate'
def test_should_show_authenticate_after_email_change(notifications_admin):
response = notifications_admin.test_client().get('/user-profile/email/authenticate')
def test_should_show_authenticate_after_email_change(app_):
response = app_.test_client().get('/user-profile/email/authenticate')
assert 'Change your email address' in response.get_data(as_text=True)
assert 'Confirm' in response.get_data(as_text=True)
assert response.status_code == 200
def test_should_redirect_after_email_change_confirm(notifications_admin):
response = notifications_admin.test_client().post('/user-profile/email/authenticate')
def test_should_redirect_after_email_change_confirm(app_):
response = app_.test_client().post('/user-profile/email/authenticate')
assert response.status_code == 302
assert response.location == 'http://localhost/user-profile/email/confirm'
def test_should_show_confirm_after_email_change(notifications_admin):
response = notifications_admin.test_client().get('/user-profile/email/confirm')
def test_should_show_confirm_after_email_change(app_):
response = app_.test_client().get('/user-profile/email/confirm')
assert 'Change your email address' in response.get_data(as_text=True)
assert 'Confirm' in response.get_data(as_text=True)
assert response.status_code == 200
def test_should_redirect_after_email_change_confirm(notifications_admin):
response = notifications_admin.test_client().post('/user-profile/email/confirm')
def test_should_redirect_after_email_change_confirm(app_):
response = app_.test_client().post('/user-profile/email/confirm')
assert response.status_code == 302
assert response.location == 'http://localhost/user-profile'
def test_should_show_mobile_number_page(notifications_admin):
response = notifications_admin.test_client().get('/user-profile/mobile-number')
def test_should_show_mobile_number_page(app_):
response = app_.test_client().get('/user-profile/mobile-number')
assert 'Change your mobile number' in response.get_data(as_text=True)
assert response.status_code == 200
def test_should_redirect_after_mobile_number_change(notifications_admin):
response = notifications_admin.test_client().post('/user-profile/email')
def test_should_redirect_after_mobile_number_change(app_):
response = app_.test_client().post('/user-profile/email')
assert response.status_code == 302
assert response.location == 'http://localhost/user-profile/email/authenticate'
def test_should_show_authenticate_after_mobile_number_change(notifications_admin):
response = notifications_admin.test_client().get('/user-profile/mobile-number/authenticate')
def test_should_show_authenticate_after_mobile_number_change(app_):
response = app_.test_client().get('/user-profile/mobile-number/authenticate')
assert 'Change your mobile number' in response.get_data(as_text=True)
assert 'Confirm' in response.get_data(as_text=True)
assert response.status_code == 200
def test_should_redirect_after_mobile_number_authenticate(notifications_admin):
response = notifications_admin.test_client().post('/user-profile/mobile-number/authenticate')
def test_should_redirect_after_mobile_number_authenticate(app_):
response = app_.test_client().post('/user-profile/mobile-number/authenticate')
assert response.status_code == 302
assert response.location == 'http://localhost/user-profile/mobile-number/confirm'
def test_should_show_confirm_after_mobile_number_change(notifications_admin):
response = notifications_admin.test_client().get('/user-profile/mobile-number/confirm')
def test_should_show_confirm_after_mobile_number_change(app_):
response = app_.test_client().get('/user-profile/mobile-number/confirm')
assert 'Change your mobile number' in response.get_data(as_text=True)
assert 'Confirm' in response.get_data(as_text=True)
assert response.status_code == 200
def test_should_redirect_after_mobile_number_confirm(notifications_admin):
response = notifications_admin.test_client().post('/user-profile/mobile-number/confirm')
def test_should_redirect_after_mobile_number_confirm(app_):
response = app_.test_client().post('/user-profile/mobile-number/confirm')
assert response.status_code == 302
assert response.location == 'http://localhost/user-profile'
def test_should_show_password_page(notifications_admin):
response = notifications_admin.test_client().get('/user-profile/password')
def test_should_show_password_page(app_):
response = app_.test_client().get('/user-profile/password')
assert 'Change your password' in response.get_data(as_text=True)
assert response.status_code == 200
def test_should_redirect_after_password_change(notifications_admin):
response = notifications_admin.test_client().post('/user-profile/password')
def test_should_redirect_after_password_change(app_):
response = app_.test_client().post('/user-profile/password')
assert response.status_code == 302
assert response.location == 'http://localhost/user-profile'

View File

@@ -3,9 +3,9 @@ from app.main.dao import users_dao, verify_codes_dao
from tests.app.main import create_test_user
def test_should_return_verify_template(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_return_verify_template(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
# TODO this lives here until we work out how to
# reassign the session after it is lost mid register process
with client.session_transaction() as session:
@@ -18,11 +18,11 @@ def test_should_return_verify_template(notifications_admin, notifications_admin_
" You need to enter both codes here.") in response.get_data(as_text=True)
def test_should_redirect_to_add_service_when_code_are_correct(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_redirect_to_add_service_when_code_are_correct(app_,
db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
user = create_test_user('pending')
session['user_email'] = user.email_address
@@ -35,9 +35,9 @@ def test_should_redirect_to_add_service_when_code_are_correct(notifications_admi
assert response.location == url_for('main.add_service', _external=True)
def test_should_activate_user_after_verify(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_activate_user_after_verify(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
user = create_test_user('pending')
session['user_email'] = user.email_address
@@ -51,9 +51,9 @@ def test_should_activate_user_after_verify(notifications_admin, notifications_ad
assert after_verify.state == 'active'
def test_should_return_200_when_codes_are_wrong(notifications_admin, notifications_admin_db, notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_return_200_when_codes_are_wrong(app_, db_, db_session):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
user = create_test_user('pending')
session['user_email'] = user.email_address
@@ -68,11 +68,11 @@ def test_should_return_200_when_codes_are_wrong(notifications_admin, notificatio
assert resp_data.count('Code does not match') == 2
def test_should_mark_all_codes_as_used_when_many_codes_exist(notifications_admin,
notifications_admin_db,
notify_db_session):
with notifications_admin.test_request_context():
with notifications_admin.test_client() as client:
def test_should_mark_all_codes_as_used_when_many_codes_exist(app_,
db_,
db_session):
with app_.test_request_context():
with app_.test_client() as client:
with client.session_transaction() as session:
user = create_test_user('pending')
session['user_email'] = user.email_address