mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-02 17:48:36 -04:00
Work in progress, skeleton of the api created and testing started. Need to fix authentication tests.
This commit is contained in:
48
tests/app/dao/test_users_dao.py
Normal file
48
tests/app/dao/test_users_dao.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from sqlalchemy.exc import DataError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from app.dao.users_dao import (create_user, get_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)
|
||||
assert User.query.count() == 1
|
||||
assert User.query.first().email_address == email
|
||||
assert User.query.filter_by(id=user_id).one()
|
||||
|
||||
|
||||
def test_get_all_users(notify_api, notify_db, notify_db_session, sample_user):
|
||||
assert User.query.count() == 1
|
||||
assert len(get_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
|
||||
|
||||
|
||||
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_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")
|
||||
pytest.fail("NoResultFound exception not thrown.")
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def test_get_user_invalid_id(notify_api, notify_db, notify_db_session):
|
||||
try:
|
||||
get_users(user_id="blah")
|
||||
pytest.fail("DataError exception not thrown.")
|
||||
except DataError:
|
||||
pass
|
||||
Reference in New Issue
Block a user