mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-25 00:33:58 -04:00
108536234: created users and roles data and domain model.
You will need to run the /scripts/bootstrap.sh to create the database for test and the app.
This commit is contained in:
32
tests/app/main/dao/test_users_dao.py
Normal file
32
tests/app/main/dao/test_users_dao.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
import sqlalchemy
|
||||
|
||||
from app.models import Users
|
||||
from app.main.dao import users_dao
|
||||
|
||||
|
||||
def test_insert_user_should_add_user(notifications_admin, notifications_admin_db):
|
||||
user = Users(name='test insert',
|
||||
password='somepassword',
|
||||
email_address='test@insert.gov.uk',
|
||||
mobile_number='+441234123412',
|
||||
created_at=datetime.now(),
|
||||
role_id=1)
|
||||
|
||||
users_dao.insert_user(user)
|
||||
saved_user = users_dao.get_user_by_id(user.id)
|
||||
assert saved_user == user
|
||||
|
||||
|
||||
def test_insert_user_with_role_that_does_not_exist_fails(notifications_admin, notifications_admin_db):
|
||||
user = Users(name='test insert',
|
||||
password='somepassword',
|
||||
email_address='test@insert.gov.uk',
|
||||
mobile_number='+441234123412',
|
||||
created_at=datetime.now(),
|
||||
role_id=100)
|
||||
with pytest.raises(sqlalchemy.exc.IntegrityError) as error:
|
||||
users_dao.insert_user(user)
|
||||
assert 'insert or update on table "users" violates foreign key constraint "users_role_id_fkey"' in str(error.value)
|
||||
Reference in New Issue
Block a user