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:
kevgliss 2016-07-07 13:03:10 -07:00 committed by GitHub
parent 1ba7181067
commit 4f3dc5422c
5 changed files with 8 additions and 11 deletions

View File

@ -102,6 +102,7 @@ class AuthorityOutputSchema(LemurOutputSchema):
class AuthorityNestedOutputSchema(LemurOutputSchema):
__envelope__ = False
id = fields.Integer()
description = fields.String()
name = fields.String()

View File

@ -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"):

View File

@ -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")

View File

@ -27,8 +27,7 @@ def update(role_id, name, description, users):
role = get(role_id)
role.name = name
role.description = description
if users:
role.users = 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)

View File

@ -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", [