mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 22:40:31 -04:00
Use decorator as decorator
This syntax makes it clearer what is being tested here, because it’s unusual to see a decorator being manually called with function as its first argument. It’s also consistent with how the later tests in this file are written.
This commit is contained in:
@@ -2,7 +2,6 @@ import pytest
|
|||||||
from flask import request
|
from flask import request
|
||||||
from werkzeug.exceptions import Forbidden
|
from werkzeug.exceptions import Forbidden
|
||||||
|
|
||||||
from app.main.views.index import index
|
|
||||||
from app.utils.user import user_has_permissions
|
from app.utils.user import user_has_permissions
|
||||||
from tests.conftest import create_user, sample_uuid
|
from tests.conftest import create_user, sample_uuid
|
||||||
|
|
||||||
@@ -30,9 +29,11 @@ def test_permissions(
|
|||||||
)
|
)
|
||||||
client_request.login(user)
|
client_request.login(user)
|
||||||
|
|
||||||
decorator = user_has_permissions(*permissions)
|
@user_has_permissions(*permissions)
|
||||||
decorated_index = decorator(index)
|
def index():
|
||||||
decorated_index()
|
pass
|
||||||
|
|
||||||
|
index()
|
||||||
|
|
||||||
|
|
||||||
def test_restrict_admin_usage(
|
def test_restrict_admin_usage(
|
||||||
@@ -42,20 +43,24 @@ def test_restrict_admin_usage(
|
|||||||
request.view_args.update({'service_id': 'foo'})
|
request.view_args.update({'service_id': 'foo'})
|
||||||
client_request.login(platform_admin_user)
|
client_request.login(platform_admin_user)
|
||||||
|
|
||||||
decorator = user_has_permissions(restrict_admin_usage=True)
|
@user_has_permissions(restrict_admin_usage=True)
|
||||||
decorated_index = decorator(index)
|
def index():
|
||||||
|
pass
|
||||||
|
|
||||||
with pytest.raises(Forbidden):
|
with pytest.raises(Forbidden):
|
||||||
decorated_index()
|
index()
|
||||||
|
|
||||||
|
|
||||||
def test_no_user_returns_redirect_to_sign_in(
|
def test_no_user_returns_redirect_to_sign_in(
|
||||||
client_request
|
client_request
|
||||||
):
|
):
|
||||||
client_request.logout()
|
client_request.logout()
|
||||||
decorator = user_has_permissions()
|
|
||||||
decorated_index = decorator(index)
|
@user_has_permissions()
|
||||||
response = decorated_index()
|
def index():
|
||||||
|
pass
|
||||||
|
|
||||||
|
response = index()
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location.startswith('/sign-in?next=')
|
assert response.location.startswith('/sign-in?next=')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user