mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
update tests to use create_user instead of sample_user
note that all of these tests have to be checked to ensure that they still call through to notify_db_session (notify_db not required) to tear down the database after the test runs - since it's no longer required to pass it in to the function just to invoke the sample_user function
This commit is contained in:
@@ -20,7 +20,7 @@ from tests.app.conftest import sample_notification as create_notification
|
||||
from tests.app.conftest import sample_job as create_job
|
||||
from tests.app.conftest import sample_service as create_service
|
||||
from tests.app.conftest import sample_template as create_template
|
||||
from tests.app.conftest import sample_user as create_user
|
||||
from tests.app.db import create_user
|
||||
|
||||
|
||||
def test_should_have_decorated_notifications_dao_functions():
|
||||
@@ -140,7 +140,7 @@ def test_get_job_by_id(sample_job):
|
||||
def test_get_jobs_for_service(notify_db, notify_db_session, sample_template):
|
||||
one_job = create_job(notify_db, notify_db_session, sample_template.service, sample_template)
|
||||
|
||||
other_user = create_user(notify_db, notify_db_session, email="test@digital.cabinet-office.gov.uk")
|
||||
other_user = create_user(email="test@digital.cabinet-office.gov.uk")
|
||||
other_service = create_service(notify_db, notify_db_session, user=other_user, service_name="other service",
|
||||
email_from='other.service')
|
||||
other_template = create_template(notify_db, notify_db_session, service=other_service)
|
||||
|
||||
@@ -16,11 +16,12 @@ from app.dao.users_dao import (
|
||||
delete_codes_older_created_more_than_a_day_ago,
|
||||
)
|
||||
|
||||
from tests.app.conftest import sample_user as create_sample_user
|
||||
from app.models import User, VerifyCode
|
||||
|
||||
from tests.app.db import create_user
|
||||
|
||||
def test_create_user(notify_api, notify_db, notify_db_session):
|
||||
|
||||
def test_create_user(notify_db_session):
|
||||
email = 'notify@digital.cabinet-office.gov.uk'
|
||||
data = {
|
||||
'name': 'Test User',
|
||||
@@ -36,53 +37,42 @@ def test_create_user(notify_api, notify_db, notify_db_session):
|
||||
assert not user.platform_admin
|
||||
|
||||
|
||||
def test_get_all_users(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert User.query.count() == 1
|
||||
assert len(get_user_by_id()) == 1
|
||||
email = "another.notify@digital.cabinet-office.gov.uk"
|
||||
another_user = create_sample_user(notify_db,
|
||||
notify_db_session,
|
||||
email=email)
|
||||
def test_get_all_users(notify_db_session):
|
||||
create_user(email='1@test.com')
|
||||
create_user(email='2@test.com')
|
||||
|
||||
assert User.query.count() == 2
|
||||
assert len(get_user_by_id()) == 2
|
||||
|
||||
|
||||
def test_get_user(notify_api, notify_db, notify_db_session):
|
||||
email = "another.notify@digital.cabinet-office.gov.uk"
|
||||
another_user = create_sample_user(notify_db,
|
||||
notify_db_session,
|
||||
email=email)
|
||||
assert get_user_by_id(user_id=another_user.id).email_address == email
|
||||
def test_get_user(notify_db_session):
|
||||
user = create_user(email='1@test.com')
|
||||
assert get_user_by_id(user_id=user.id).email_address == email
|
||||
|
||||
|
||||
def test_get_user_not_exists(notify_api, notify_db, notify_db_session, fake_uuid):
|
||||
try:
|
||||
def test_get_user_not_exists(notify_db, fake_uuid):
|
||||
with pytest.raises(NoResultFound):
|
||||
get_user_by_id(user_id=fake_uuid)
|
||||
pytest.fail("NoResultFound exception not thrown.")
|
||||
except NoResultFound as e:
|
||||
pass
|
||||
|
||||
|
||||
def test_get_user_invalid_id(notify_api, notify_db, notify_db_session):
|
||||
def test_get_user_invalid_id(notify_db):
|
||||
with pytest.raises(DataError):
|
||||
get_user_by_id(user_id="blah")
|
||||
|
||||
|
||||
def test_delete_users(notify_api, notify_db, notify_db_session, sample_user):
|
||||
def test_delete_users(sample_user):
|
||||
assert User.query.count() == 1
|
||||
delete_model_user(sample_user)
|
||||
assert User.query.count() == 0
|
||||
|
||||
|
||||
def test_increment_failed_login_should_increment_failed_logins(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert User.query.count() == 1
|
||||
def test_increment_failed_login_should_increment_failed_logins(sample_user):
|
||||
assert sample_user.failed_login_count == 0
|
||||
increment_failed_login_count(sample_user)
|
||||
assert sample_user.failed_login_count == 1
|
||||
|
||||
|
||||
def test_reset_failed_login_should_set_failed_logins_to_0(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert User.query.count() == 1
|
||||
def test_reset_failed_login_should_set_failed_logins_to_0(sample_user):
|
||||
increment_failed_login_count(sample_user)
|
||||
assert sample_user.failed_login_count == 1
|
||||
reset_failed_login_count(sample_user)
|
||||
@@ -90,8 +80,7 @@ def test_reset_failed_login_should_set_failed_logins_to_0(notify_api, notify_db,
|
||||
|
||||
|
||||
def test_get_user_by_email(sample_user):
|
||||
email = sample_user.email_address
|
||||
user_from_db = get_user_by_email(email)
|
||||
user_from_db = get_user_by_email(sample_user.email_address)
|
||||
assert sample_user == user_from_db
|
||||
|
||||
|
||||
@@ -104,19 +93,18 @@ def test_get_user_by_email_is_case_insensitive(sample_user):
|
||||
def test_should_delete_all_verification_codes_more_than_one_day_old(sample_user):
|
||||
make_verify_code(sample_user, age=timedelta(hours=24), code="54321")
|
||||
make_verify_code(sample_user, age=timedelta(hours=24), code="54321")
|
||||
assert len(VerifyCode.query.all()) == 2
|
||||
assert VerifyCode.query.count() == 2
|
||||
delete_codes_older_created_more_than_a_day_ago()
|
||||
assert len(VerifyCode.query.all()) == 0
|
||||
assert VerifyCode.query.count() == 0
|
||||
|
||||
|
||||
def test_should_not_delete_verification_codes_less_than_one_day_old(sample_user):
|
||||
make_verify_code(sample_user, age=timedelta(hours=23, minutes=59, seconds=59), code="12345")
|
||||
make_verify_code(sample_user, age=timedelta(hours=24), code="54321")
|
||||
|
||||
assert len(VerifyCode.query.all()) == 2
|
||||
assert VerifyCode.query.count() == 2
|
||||
delete_codes_older_created_more_than_a_day_ago()
|
||||
assert len(VerifyCode.query.all()) == 1
|
||||
assert VerifyCode.query.first()._code == "12345"
|
||||
assert VerifyCode.query.one()._code == "12345"
|
||||
|
||||
|
||||
def make_verify_code(user, age=timedelta(hours=0), code="12335"):
|
||||
|
||||
Reference in New Issue
Block a user