No more need for mock roles

This commit is contained in:
0mar
2020-12-16 14:46:08 +01:00
parent 3eccf7abdd
commit f10fc0f0c0
2 changed files with 51 additions and 71 deletions

View File

@@ -78,13 +78,6 @@ def mock_open_session(username, service, encoding):
pass
def mock_role(app, role='admin', name=None):
scopes = get_scopes(role)
if name is not None:
scopes = [scope.format(username=name) for scope in scopes]
return mock.patch.dict(app.tornado_settings, {'mock_scopes': scopes})
class MockSpawner(SimpleLocalProcessSpawner):
"""Base mock spawner

View File

@@ -18,7 +18,6 @@ from .. import roles
from ..objects import Server
from ..utils import url_path_join as ujoin
from ..utils import utcnow
from .mocking import mock_role
from .mocking import public_host
from .mocking import public_url
from .utils import add_user
@@ -181,7 +180,6 @@ async def test_get_users(app):
{'name': 'user', 'admin': False, 'roles': ['user'], 'last_activity': None}
),
]
with mock_role(app, 'user'):
r = await api_request(app, 'users', headers=auth_header(db, 'user'))
assert r.status_code == 403
@@ -284,7 +282,6 @@ async def test_get_self(app):
assert model['name'] == u.name
# invalid auth gets 403
with mock_role(app, 'user'):
r = await api_request(
app,
'user',
@@ -314,7 +311,6 @@ async def test_add_user(app):
async def test_get_user(app):
name = 'user'
_ = await api_request(app, 'users', name, headers=auth_header(app.db, name))
with mock_role(app, role=name, name=name):
r = await api_request(
app,
'users',
@@ -518,7 +514,6 @@ async def test_user_set_auth_state(app, auth_state_enabled):
assert user.name == name
user_auth_state = await user.get_auth_state()
assert user_auth_state is None
with mock_role(app, 'user'):
r = await api_request(
app,
'users',
@@ -1348,7 +1343,6 @@ async def test_token_authenticator_noauth(app):
"""Create a token for a user relying on Authenticator.authenticate and no auth header"""
name = 'user'
data = {'auth': {'username': name, 'password': name}}
with mock_role(app, 'admin'):
r = await api_request(
app,
'users',
@@ -1372,7 +1366,6 @@ async def test_token_authenticator_dict_noauth(app):
app.authenticator.auth_state = {'who': 'cares'}
name = 'user'
data = {'auth': {'username': name, 'password': name}}
with mock_role(app, 'user'):
r = await api_request(
app,
'users',
@@ -1405,7 +1398,6 @@ async def test_token_list(app, as_user, for_user, status):
if for_user != 'missing':
for_user_obj = add_user(app.db, app, name=for_user)
headers = {'Authorization': 'token %s' % u.new_api_token()}
with mock_role(app, role=as_user, name=as_user):
r = await api_request(app, 'users', for_user, 'tokens', headers=headers)
assert r.status_code == status
if status != 200:
@@ -1417,7 +1409,6 @@ async def test_token_list(app, as_user, for_user, status):
assert all(token['user'] == for_user for token in reply['oauth_tokens'])
# validate individual token ids
for token in reply['api_tokens'] + reply['oauth_tokens']:
with mock_role(app, role=as_user, name=as_user):
r = await api_request(
app, 'users', for_user, 'tokens', token['id'], headers=headers
)
@@ -1603,7 +1594,6 @@ async def test_get_services(app, mockservice_url):
'display': True,
}
}
with mock_role(app, 'user'):
r = await api_request(app, 'services', headers=auth_header(db, 'user'))
assert r.status_code == 403
@@ -1647,7 +1637,6 @@ async def test_root_api(app):
if app.internal_ssl:
kwargs['cert'] = (app.internal_ssl_cert, app.internal_ssl_key)
kwargs["verify"] = app.internal_ssl_ca
with mock_role(app):
r = await api_request(app, bypass_proxy=True)
r.raise_for_status()
expected = {'version': jupyterhub.__version__}
@@ -1655,7 +1644,6 @@ async def test_root_api(app):
async def test_info(app):
with mock_role(app):
r = await api_request(app, 'info')
r.raise_for_status()
data = r.json()
@@ -1686,7 +1674,6 @@ async def test_info(app):
async def test_update_activity_403(app, user, admin_user):
token = user.new_api_token()
with mock_role(app, 'user'):
r = await api_request(
app,
"users/{}/activity".format(admin_user.name),