2015-11-25 15:29:12 +00:00
|
|
|
import pytest
|
|
|
|
|
import sqlalchemy
|
|
|
|
|
|
|
|
|
|
from app.models import Roles
|
|
|
|
|
from app.main.dao import roles_dao
|
|
|
|
|
|
|
|
|
|
|
2015-12-10 14:48:01 +00:00
|
|
|
def test_insert_role_should_be_able_to_get_role(notifications_admin, notifications_admin_db, notify_db_session):
|
2015-11-25 15:29:12 +00:00
|
|
|
role = Roles(id=1000, role='some role for test')
|
|
|
|
|
roles_dao.insert_role(role)
|
|
|
|
|
|
|
|
|
|
saved_role = roles_dao.get_role_by_id(role.id)
|
|
|
|
|
assert saved_role == role
|
|
|
|
|
|
|
|
|
|
|
2015-12-10 14:48:01 +00:00
|
|
|
def test_insert_role_will_throw_error_if_role_already_exists(notifications_admin,
|
|
|
|
|
notifications_admin_db,
|
|
|
|
|
notify_db_session):
|
2015-11-27 09:47:29 +00:00
|
|
|
role1 = roles_dao.get_role_by_id(1)
|
|
|
|
|
assert role1.id == 1
|
|
|
|
|
|
2015-11-25 15:29:12 +00:00
|
|
|
role = Roles(id=1, role='cannot create a duplicate')
|
|
|
|
|
|
2015-11-27 09:47:29 +00:00
|
|
|
with pytest.raises(sqlalchemy.orm.exc.FlushError) as error:
|
2015-11-25 15:29:12 +00:00
|
|
|
roles_dao.insert_role(role)
|
2015-11-27 09:47:29 +00:00
|
|
|
assert 'conflicts with persistent instance' in str(error.value)
|