mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-06 05:58:25 -04:00
Fix all tests.
This commit is contained in:
@@ -8,7 +8,9 @@ from app.models import (
|
|||||||
MANAGE_SERVICE,
|
MANAGE_SERVICE,
|
||||||
SEND_MESSAGES,
|
SEND_MESSAGES,
|
||||||
MANAGE_API_KEYS,
|
MANAGE_API_KEYS,
|
||||||
MANAGE_TEMPLATES)
|
MANAGE_TEMPLATES,
|
||||||
|
MANAGE_TEAM,
|
||||||
|
VIEW_ACTIVITY)
|
||||||
|
|
||||||
|
|
||||||
# Default permissions for a service
|
# Default permissions for a service
|
||||||
@@ -16,7 +18,10 @@ default_service_permissions = [
|
|||||||
MANAGE_SERVICE,
|
MANAGE_SERVICE,
|
||||||
SEND_MESSAGES,
|
SEND_MESSAGES,
|
||||||
MANAGE_API_KEYS,
|
MANAGE_API_KEYS,
|
||||||
MANAGE_TEMPLATES]
|
MANAGE_TEMPLATES,
|
||||||
|
MANAGE_TEAM,
|
||||||
|
VIEW_ACTIVITY]
|
||||||
|
|
||||||
|
|
||||||
class PermissionDAO(DAOClass):
|
class PermissionDAO(DAOClass):
|
||||||
|
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ def sample_permission(notify_db,
|
|||||||
notify_db_session,
|
notify_db_session,
|
||||||
service=None,
|
service=None,
|
||||||
user=None,
|
user=None,
|
||||||
permission="sample permission"):
|
permission="manage_service"):
|
||||||
if user is None:
|
if user is None:
|
||||||
user = sample_user(notify_db, notify_db_session)
|
user = sample_user(notify_db, notify_db_session)
|
||||||
data = {
|
data = {
|
||||||
@@ -333,9 +333,14 @@ def sample_permission(notify_db,
|
|||||||
}
|
}
|
||||||
if service:
|
if service:
|
||||||
data['service'] = service
|
data['service'] = service
|
||||||
p_model = Permission(**data)
|
p_model = Permission.query.filter_by(
|
||||||
db.session.add(p_model)
|
user=user,
|
||||||
db.session.commit()
|
service=service,
|
||||||
|
permission=permission).first()
|
||||||
|
if not p_model:
|
||||||
|
p_model = Permission(**data)
|
||||||
|
db.session.add(p_model)
|
||||||
|
db.session.commit()
|
||||||
return p_model
|
return p_model
|
||||||
|
|
||||||
|
|
||||||
@@ -344,7 +349,7 @@ def sample_service_permission(notify_db,
|
|||||||
notify_db_session,
|
notify_db_session,
|
||||||
service=None,
|
service=None,
|
||||||
user=None,
|
user=None,
|
||||||
permission="sample permission"):
|
permission="manage_service"):
|
||||||
if user is None:
|
if user is None:
|
||||||
user = sample_user(notify_db, notify_db_session)
|
user = sample_user(notify_db, notify_db_session)
|
||||||
if service is None:
|
if service is None:
|
||||||
@@ -354,7 +359,12 @@ def sample_service_permission(notify_db,
|
|||||||
'service': service,
|
'service': service,
|
||||||
'permission': permission
|
'permission': permission
|
||||||
}
|
}
|
||||||
p_model = Permission(**data)
|
p_model = Permission.query.filter_by(
|
||||||
db.session.add(p_model)
|
user=user,
|
||||||
db.session.commit()
|
service=service,
|
||||||
|
permission=permission).first()
|
||||||
|
if not p_model:
|
||||||
|
p_model = Permission(**data)
|
||||||
|
db.session.add(p_model)
|
||||||
|
db.session.commit()
|
||||||
return p_model
|
return p_model
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
|
from app.models import Permission
|
||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
from ..conftest import sample_permission as create_permission
|
from ..conftest import sample_permission as create_permission
|
||||||
|
|
||||||
@@ -39,12 +40,6 @@ def test_get_permission_filter(notify_api,
|
|||||||
"""
|
"""
|
||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
another_permission = create_permission(
|
|
||||||
notify_db,
|
|
||||||
notify_db_session,
|
|
||||||
user=sample_user,
|
|
||||||
service=sample_service,
|
|
||||||
permission="another permission")
|
|
||||||
header = create_authorization_header(
|
header = create_authorization_header(
|
||||||
path=url_for('permission.get_permissions'),
|
path=url_for('permission.get_permissions'),
|
||||||
method='GET')
|
method='GET')
|
||||||
@@ -53,6 +48,8 @@ def test_get_permission_filter(notify_api,
|
|||||||
headers=[header])
|
headers=[header])
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
json_resp = json.loads(response.get_data(as_text=True))
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
|
another_permission = Permission.query.filter_by(
|
||||||
|
service_id=str(sample_service.id)).first()
|
||||||
expected = {
|
expected = {
|
||||||
"permission": another_permission.permission,
|
"permission": another_permission.permission,
|
||||||
"user": sample_user.id,
|
"user": sample_user.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user