Allowing the role-user associated to be updated. (#396)
* Allowing the role-user associated to be updated. * Fixing tests * Fixing tests, for real.
This commit is contained in:
parent
1ba7181067
commit
4f3dc5422c
|
@ -102,6 +102,7 @@ class AuthorityOutputSchema(LemurOutputSchema):
|
|||
|
||||
|
||||
class AuthorityNestedOutputSchema(LemurOutputSchema):
|
||||
__envelope__ = False
|
||||
id = fields.Integer()
|
||||
description = fields.String()
|
||||
name = fields.String()
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
from sqlalchemy import exc
|
||||
from sqlalchemy.sql import and_, or_
|
||||
from sqlalchemy.orm import make_transient
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
|
||||
from lemur.extensions import db
|
||||
from lemur.exceptions import AttrNotFound, DuplicateError
|
||||
|
@ -125,10 +123,7 @@ def get(model, value, field="id"):
|
|||
:return:
|
||||
"""
|
||||
query = session_query(model)
|
||||
try:
|
||||
return query.filter(getattr(model, field) == value).one()
|
||||
except NoResultFound as e:
|
||||
return
|
||||
return query.filter(getattr(model, field) == value).scalar()
|
||||
|
||||
|
||||
def get_all(model, value, field="id"):
|
||||
|
|
|
@ -27,5 +27,5 @@ class Role(db.Model):
|
|||
authority_id = Column(Integer, ForeignKey('authorities.id'))
|
||||
authorities = relationship("Authority", secondary=roles_authorities, passive_deletes=True, backref="role", cascade='all,delete')
|
||||
user_id = Column(Integer, ForeignKey('users.id'))
|
||||
users = relationship("User", secondary=roles_users, viewonly=True, backref="role")
|
||||
users = relationship("User", secondary=roles_users, passive_deletes=True, backref="role")
|
||||
certificates = relationship("Certificate", secondary=roles_certificates, backref="role")
|
||||
|
|
|
@ -27,7 +27,6 @@ def update(role_id, name, description, users):
|
|||
role = get(role_id)
|
||||
role.name = name
|
||||
role.description = description
|
||||
if users:
|
||||
role.users = users
|
||||
database.update(role)
|
||||
return role
|
||||
|
@ -45,8 +44,10 @@ def create(name, password=None, description=None, username=None, users=None):
|
|||
:return:
|
||||
"""
|
||||
role = Role(name=name, description=description, username=username, password=password)
|
||||
|
||||
if users:
|
||||
role.users = users
|
||||
|
||||
return database.create(role)
|
||||
|
||||
|
||||
|
|
|
@ -70,8 +70,8 @@ def test_role_put(client, token, status):
|
|||
(VALID_ADMIN_HEADER_TOKEN, 200),
|
||||
('', 401)
|
||||
])
|
||||
def test_role_delete(client, token, status):
|
||||
assert client.delete(api.url_for(Roles, role_id=1), headers=token).status_code == status
|
||||
def test_role_delete(client, token, status, role):
|
||||
assert client.delete(api.url_for(Roles, role_id=role.id), headers=token).status_code == status
|
||||
|
||||
|
||||
@pytest.mark.parametrize("token,status", [
|
||||
|
|
Loading…
Reference in New Issue