mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 22:39:43 -04:00
Added more tests
This commit is contained in:
@@ -16,12 +16,12 @@ from app.dao.organisation_dao import (
|
||||
)
|
||||
from app.models import Organisation
|
||||
|
||||
from tests.app.db import create_organisation, create_service, create_invited_org_user, create_user
|
||||
from tests.app.db import create_organisation, create_service, create_user
|
||||
|
||||
|
||||
def test_get_organisations_gets_all_organisations_alphabetically_with_active_organisations_first(
|
||||
notify_db,
|
||||
notify_db_session
|
||||
notify_db,
|
||||
notify_db_session
|
||||
):
|
||||
m_active_org = create_organisation(name='m_active_organisation')
|
||||
z_inactive_org = create_organisation(name='z_inactive_organisation', active=False)
|
||||
@@ -134,3 +134,46 @@ def test_dao_get_users_for_organisation(sample_organisation):
|
||||
assert results[0] == first
|
||||
assert results[1] == second
|
||||
|
||||
|
||||
def test_dao_get_users_for_organisation_returns_empty_list(sample_organisation):
|
||||
results = dao_get_users_for_organisation(organisation_id=sample_organisation.id)
|
||||
assert len(results) == 0
|
||||
|
||||
|
||||
def test_dao_get_users_for_organisation_only_returns_active_users(sample_organisation):
|
||||
first = create_user(email='first@invited.com')
|
||||
second = create_user(email='another@invited.com')
|
||||
|
||||
dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=first.id)
|
||||
dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=second.id)
|
||||
|
||||
second.state = 'inactive'
|
||||
|
||||
results = dao_get_users_for_organisation(organisation_id=sample_organisation.id)
|
||||
assert len(results) == 1
|
||||
assert results[0] == first
|
||||
|
||||
|
||||
def test_add_user_to_organisation_returns_user(sample_organisation):
|
||||
org_user = create_user()
|
||||
assert not org_user.organisations
|
||||
|
||||
added_user = dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=org_user.id)
|
||||
assert len(added_user.organisations) == 1
|
||||
assert added_user.organisations[0] == sample_organisation
|
||||
|
||||
|
||||
def test_add_user_to_organisation_when_user_does_not_exist(sample_organisation):
|
||||
with pytest.raises(expected_exception=SQLAlchemyError):
|
||||
dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=uuid.uuid4())
|
||||
|
||||
|
||||
def test_add_user_to_organisation_when_organisation_does_not_exist(sample_user):
|
||||
with pytest.raises(expected_exception=SQLAlchemyError):
|
||||
dao_add_user_to_organisation(organisation_id=uuid.uuid4(), user_id=sample_user.id)
|
||||
|
||||
|
||||
def test_add_user_to_organisation_raises_exception_when_user_is_not_active(sample_organisation):
|
||||
first = create_user(state='inactive')
|
||||
with pytest.raises(expected_exception=SQLAlchemyError):
|
||||
dao_add_user_to_organisation(organisation_id=sample_organisation.id, user_id=first.id)
|
||||
|
||||
Reference in New Issue
Block a user