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

@@ -6,7 +6,7 @@ from app.models import User
from app.main.dao import users_dao
@pytest.mark.xfail(reason='Tests will be moved to api')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_insert_user_should_add_user(db_, db_session):
user = User(name='test insert',
password='somepassword',
@@ -19,7 +19,7 @@ def test_insert_user_should_add_user(db_, db_session):
assert saved_user == user
@pytest.mark.xfail(reason='Tests will be moved to api')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_insert_user_with_role_that_does_not_exist_fails(db_, db_session):
user = User(name='role does not exist',
password='somepassword',
@@ -31,7 +31,7 @@ def test_insert_user_with_role_that_does_not_exist_fails(db_, db_session):
assert 'insert or update on table "users" violates foreign key constraint "users_role_id_fkey"' in str(error.value)
@pytest.mark.xfail(reason='Not implemented yet on api client')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_get_user_by_email(db_, db_session):
user = User(name='test_get_by_email',
password='somepassword',
@@ -44,7 +44,7 @@ def test_get_user_by_email(db_, db_session):
assert retrieved == user
@pytest.mark.xfail(reason='Not implemented yet on api client')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_get_all_users_returns_all_users(db_, db_session):
user1 = User(name='test one',
password='somepassword',
@@ -70,7 +70,7 @@ def test_get_all_users_returns_all_users(db_, db_session):
assert users == [user1, user2, user3]
@pytest.mark.xfail(reason='Not implemented yet on api client')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_increment_failed_lockout_count_should_increade_count_by_1(db_, db_session):
user = User(name='cannot remember password',
password='somepassword',
@@ -85,7 +85,7 @@ def test_increment_failed_lockout_count_should_increade_count_by_1(db_, db_sessi
assert users_dao.get_user_by_id(user.id).failed_login_count == 1
@pytest.mark.xfail(reason='Not implemented yet on api client')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_user_is_locked_if_failed_login_count_is_10_or_greater(db_, db_session):
user = User(name='cannot remember password',
password='somepassword',
@@ -104,7 +104,7 @@ def test_user_is_locked_if_failed_login_count_is_10_or_greater(db_, db_session):
assert saved_user.is_locked() is True
@pytest.mark.xfail(reason='Not implemented yet on api client')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_user_is_active_is_false_if_state_is_inactive(db_, db_session):
user = User(name='inactive user',
password='somepassword',
@@ -131,14 +131,14 @@ def test_should_update_user_to_active(mock_activate_user):
assert activated_user.state == 'active'
@pytest.mark.xfail(reason='Not implemented yet on api client')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_should_throws_error_when_id_does_not_exist(db_, db_session):
with pytest.raises(AttributeError) as error:
users_dao.activate_user(123)
assert '''object has no attribute 'state''''' in str(error.value)
@pytest.mark.xfail(reason='Not implemented yet on api client')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_should_update_email_address(db_, db_session):
user = User(name='Update Email',
password='somepassword',
@@ -155,7 +155,7 @@ def test_should_update_email_address(db_, db_session):
assert updated.email_address == 'new_email@testit.gov.uk'
@pytest.mark.xfail(reason='Not implemented yet on api client')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_should_update_password(db_, db_session):
user = User(name='Update Email',
password='somepassword',
@@ -176,7 +176,7 @@ def test_should_update_password(db_, db_session):
assert updated.password_changed_at > start
@pytest.mark.xfail(reason='Not implemented yet on api client')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_should_return_list_of_all_email_addresses(db_, db_session):
first = User(name='First Person',
password='somepassword',
@@ -198,7 +198,7 @@ def test_should_return_list_of_all_email_addresses(db_, db_session):
assert expected == [x.email_address for x in email_addresses]
@pytest.mark.xfail(reason='Not implemented yet on api client')
@pytest.mark.skipif(True, reason='Database tests to move to api and ineraction tests done here')
def test_should_update_state_to_request_password_reset(db_, db_session):
user = User(name='Requesting Password Resest',
password='somepassword',