Reintroduce some tests. A bit of cleanup of mocks.

User object fields made a bit clearer and simple test to
verify user added.
This commit is contained in:
Adam Shimali
2016-01-23 23:14:50 +00:00
parent ba0d0d49e1
commit 4674bd6b68
23 changed files with 493 additions and 453 deletions

View File

@@ -1,11 +1,5 @@
from datetime import datetime
from app.main.dao import users_dao
from app.models import User
from flask import url_for
import pytest
def test_render_sign_in_returns_sign_in_template(app_):
with app_.test_request_context():
@@ -20,12 +14,11 @@ def test_render_sign_in_returns_sign_in_template(app_):
def test_logged_in_user_redirects_to_choose_service(app_,
db_,
db_session,
mock_api_user,
mock_user_loader,
mock_user_dao_get_by_email):
mock_active_user,
mock_get_by_email):
with app_.test_request_context():
with app_.test_client() as client:
client.login(mock_api_user)
client.login(mock_active_user)
response = client.get(url_for('main.sign_in'))
assert response.status_code == 302
@@ -38,10 +31,9 @@ def test_process_sign_in_return_2fa_template(app_,
db_session,
mock_send_sms,
mock_send_email,
mock_user_dao_get_user,
mock_user_loader,
mock_user_dao_get_by_email,
mock_user_dao_checkpassword):
mock_get_user,
mock_get_by_email,
mock_user_checkpassword):
with app_.test_request_context():
response = app_.test_client().post(
url_for('main.sign_in'), data={
@@ -51,16 +43,12 @@ def test_process_sign_in_return_2fa_template(app_,
assert response.location == 'http://localhost/two-factor'
def test_should_return_locked_out_true_when_user_is_locked(app_,
db_,
db_session,
mock_user_dao_get_user,
mock_inactive_user_dao_get_by_email):
def test_should_return_locked_out_true_when_user_is_locked(app_, mock_get_by_email):
with app_.test_request_context():
for _ in range(10):
app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'valid@example.gov.uk',
'email_address': 'locked_user@example.gov.uk',
'password': 'whatIsMyPassword!'})
response = app_.test_client().post(
@@ -79,11 +67,8 @@ def test_should_return_locked_out_true_when_user_is_locked(app_,
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(app_,
db_,
db_session,
mock_user_dao_get_user,
mock_inactive_user_dao_get_by_email):
def test_should_return_active_user_is_false_if_user_is_inactive(app_, mock_get_by_email):
with app_.test_request_context():
response = app_.test_client().post(
url_for('main.sign_in'), data={
@@ -94,29 +79,21 @@ def test_should_return_active_user_is_false_if_user_is_inactive(app_,
assert 'Username or password is incorrect' in response.get_data(as_text=True)
def test_should_return_200_when_user_does_not_exist(app_,
db_,
db_session,
mock_user_dao_get_user,
mock_user_dao_get_by_email):
def test_should_return_200_when_user_does_not_exist(app_, mock_get_by_email):
with app_.test_request_context():
response = app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'does_not_exist@gov.uk',
'email_address': 'notfound@gov.uk',
'password': 'doesNotExist!'})
assert response.status_code == 200
assert 'Username or password is incorrect' in response.get_data(as_text=True)
def test_should_return_200_when_user_is_not_active(app_,
db_,
db_session,
mock_user_dao_get_user,
mock_user_dao_get_by_email):
def test_should_return_200_when_user_is_not_active(app_, mock_get_by_email):
with app_.test_request_context():
response = app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'PendingUser@example.gov.uk',
'email_address': 'pending_user@example.gov.uk',
'password': 'val1dPassw0rd!'})
assert response.status_code == 200
assert 'Username or password is incorrect' in response.get_data(as_text=True)