mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-06 00:28:25 -04:00
Service and User API added, working with tests. Still need to polish the edges and add more tests.
This commit is contained in:
@@ -1,27 +1,28 @@
|
||||
from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from app.dao.users_dao import (create_user, get_users)
|
||||
from app.dao.users_dao import (create_model_user, get_model_users)
|
||||
from tests.app.conftest import sample_user as create_sample_user
|
||||
from app.models import User
|
||||
|
||||
|
||||
def test_create_user(notify_api, notify_db, notify_db_session):
|
||||
email = 'notify@digital.cabinet-office.gov.uk'
|
||||
user_id = create_user(email)
|
||||
user = User(**{'email_address': email})
|
||||
create_model_user(user)
|
||||
assert User.query.count() == 1
|
||||
assert User.query.first().email_address == email
|
||||
assert User.query.filter_by(id=user_id).one()
|
||||
assert User.query.first().id == user.id
|
||||
|
||||
|
||||
def test_get_all_users(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert User.query.count() == 1
|
||||
assert len(get_users()) == 1
|
||||
assert len(get_model_users()) == 1
|
||||
email = "another.notify@digital.cabinet-office.gov.uk"
|
||||
another_user = create_sample_user(notify_db,
|
||||
notify_db_session,
|
||||
email=email)
|
||||
assert User.query.count() == 2
|
||||
assert len(get_users()) == 2
|
||||
assert len(get_model_users()) == 2
|
||||
|
||||
|
||||
def test_get_user(notify_api, notify_db, notify_db_session):
|
||||
@@ -29,12 +30,12 @@ def test_get_user(notify_api, notify_db, notify_db_session):
|
||||
another_user = create_sample_user(notify_db,
|
||||
notify_db_session,
|
||||
email=email)
|
||||
assert get_users(user_id=another_user.id).email_address == email
|
||||
assert get_model_users(user_id=another_user.id).email_address == email
|
||||
|
||||
|
||||
def test_get_user_not_exists(notify_api, notify_db, notify_db_session):
|
||||
try:
|
||||
get_users(user_id="12345")
|
||||
get_model_users(user_id="12345")
|
||||
pytest.fail("NoResultFound exception not thrown.")
|
||||
except:
|
||||
pass
|
||||
@@ -42,7 +43,7 @@ def test_get_user_not_exists(notify_api, notify_db, notify_db_session):
|
||||
|
||||
def test_get_user_invalid_id(notify_api, notify_db, notify_db_session):
|
||||
try:
|
||||
get_users(user_id="blah")
|
||||
get_model_users(user_id="blah")
|
||||
pytest.fail("DataError exception not thrown.")
|
||||
except DataError:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user