Limit robots displayed in entity search
Before, we'd load *all* the robots, which can be a huge issue in namespaces with a large number of robots. Now, we only load the top-20 robots (as per recency in login), and we also limit the information returned to the entity search to save some bandwidth. Fixes https://jira.coreos.com/browse/QUAY-927
This commit is contained in:
parent
7878435805
commit
5c50161d85
7 changed files with 121 additions and 26 deletions
|
@ -4,7 +4,7 @@ import json
|
|||
from data import model
|
||||
from endpoints.api import api
|
||||
from endpoints.api.test.shared import conduct_api_call
|
||||
from endpoints.api.robot import UserRobot, OrgRobot
|
||||
from endpoints.api.robot import UserRobot, OrgRobot, UserRobotList, OrgRobotList
|
||||
from endpoints.test.shared import client_with_identity
|
||||
|
||||
from test.test_ldap import mock_ldap
|
||||
|
@ -36,3 +36,63 @@ def test_create_robot_with_metadata(endpoint, body, client):
|
|||
body = body or {}
|
||||
assert resp.json['description'] == (body.get('description') or '')
|
||||
assert resp.json['unstructured_metadata'] == (body.get('unstructured_metadata') or {})
|
||||
|
||||
|
||||
@pytest.mark.parametrize('endpoint, params', [
|
||||
(UserRobot, {'robot_shortname': 'dtrobot'}),
|
||||
(OrgRobot, {'orgname': 'buynlarge', 'robot_shortname': 'coolrobot'}),
|
||||
])
|
||||
def test_retrieve_robot(endpoint, params, app, client):
|
||||
with client_with_identity('devtable', client) as cl:
|
||||
result = conduct_api_call(cl, endpoint, 'GET', params, None)
|
||||
assert result.json['token'] is not None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('endpoint, params', [
|
||||
(UserRobotList, {}),
|
||||
(OrgRobotList, {'orgname': 'buynlarge'}),
|
||||
])
|
||||
@pytest.mark.parametrize('include_token', [
|
||||
True,
|
||||
False,
|
||||
])
|
||||
@pytest.mark.parametrize('limit', [
|
||||
None,
|
||||
1,
|
||||
5,
|
||||
])
|
||||
def test_retrieve_robots(endpoint, params, include_token, limit, app, client):
|
||||
params['token'] = 'true' if include_token else 'false'
|
||||
|
||||
if limit is not None:
|
||||
params['limit'] = limit
|
||||
|
||||
with client_with_identity('devtable', client) as cl:
|
||||
result = conduct_api_call(cl, endpoint, 'GET', params, None)
|
||||
|
||||
if limit is not None:
|
||||
assert len(result.json['robots']) <= limit
|
||||
|
||||
for robot in result.json['robots']:
|
||||
assert (robot.get('token') is not None) == include_token
|
||||
|
||||
|
||||
@pytest.mark.parametrize('username, is_admin', [
|
||||
('devtable', True),
|
||||
('reader', False),
|
||||
])
|
||||
@pytest.mark.parametrize('with_permissions', [
|
||||
True,
|
||||
False,
|
||||
])
|
||||
def test_retrieve_robots_token_permission(username, is_admin, with_permissions, app, client):
|
||||
with client_with_identity(username, client) as cl:
|
||||
params = {'orgname': 'buynlarge', 'token': 'true'}
|
||||
if with_permissions:
|
||||
params['permissions'] = 'true'
|
||||
|
||||
result = conduct_api_call(cl, OrgRobotList, 'GET', params, None)
|
||||
assert result.json['robots']
|
||||
for robot in result.json['robots']:
|
||||
assert (robot.get('token') is not None) == is_admin
|
||||
assert (robot.get('repositories') is not None) == (is_admin and with_permissions)
|
||||
|
|
Reference in a new issue