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

@@ -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