mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-14 13:33:00 +00:00
Add pagination tests for users/groups/group users
This commit is contained in:
@@ -178,6 +178,30 @@ async def test_get_users(app):
|
|||||||
r = await api_request(app, 'users', headers=auth_header(db, 'user'))
|
r = await api_request(app, 'users', headers=auth_header(db, 'user'))
|
||||||
assert r.status_code == 403
|
assert r.status_code == 403
|
||||||
|
|
||||||
|
# Tests offset for pagination
|
||||||
|
r = await api_request(app, 'users?offset=1')
|
||||||
|
assert r.status_code == 200
|
||||||
|
|
||||||
|
users = sorted(r.json(), key=lambda d: d['name'])
|
||||||
|
users = [normalize_user(u) for u in users]
|
||||||
|
assert users == [fill_user({'name': 'user', 'admin': False})]
|
||||||
|
|
||||||
|
r = await api_request(app, 'users?offset=20')
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.json() == []
|
||||||
|
|
||||||
|
# Test limit for pagination
|
||||||
|
r = await api_request(app, 'users?limit=1')
|
||||||
|
assert r.status_code == 200
|
||||||
|
|
||||||
|
users = sorted(r.json(), key=lambda d: d['name'])
|
||||||
|
users = [normalize_user(u) for u in users]
|
||||||
|
assert users == [fill_user({'name': 'admin', 'admin': True})]
|
||||||
|
|
||||||
|
r = await api_request(app, 'users?limit=0')
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.json() == []
|
||||||
|
|
||||||
|
|
||||||
@mark.user
|
@mark.user
|
||||||
@mark.parametrize(
|
@mark.parametrize(
|
||||||
@@ -1401,16 +1425,45 @@ async def test_groups_list(app):
|
|||||||
reply = r.json()
|
reply = r.json()
|
||||||
assert reply == []
|
assert reply == []
|
||||||
|
|
||||||
# create a group
|
# create two groups
|
||||||
group = orm.Group(name='alphaflight')
|
group = orm.Group(name='alphaflight')
|
||||||
|
group_2 = orm.Group(name='betaflight')
|
||||||
app.db.add(group)
|
app.db.add(group)
|
||||||
|
app.db.add(group_2)
|
||||||
app.db.commit()
|
app.db.commit()
|
||||||
|
|
||||||
r = await api_request(app, 'groups')
|
r = await api_request(app, 'groups')
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
reply = r.json()
|
reply = r.json()
|
||||||
|
assert reply == [
|
||||||
|
{'kind': 'group', 'name': 'alphaflight', 'users': []},
|
||||||
|
{'kind': 'group', 'name': 'betaflight', 'users': []},
|
||||||
|
]
|
||||||
|
|
||||||
|
# Test offset for pagination
|
||||||
|
r = await api_request(app, "groups?offset=1")
|
||||||
|
r.raise_for_status()
|
||||||
|
reply = r.json()
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert reply == [{'kind': 'group', 'name': 'betaflight', 'users': []}]
|
||||||
|
|
||||||
|
r = await api_request(app, "groups?offset=10")
|
||||||
|
r.raise_for_status()
|
||||||
|
reply = r.json()
|
||||||
|
assert reply == []
|
||||||
|
|
||||||
|
# Test limit for pagination
|
||||||
|
r = await api_request(app, "groups?limit=1")
|
||||||
|
r.raise_for_status()
|
||||||
|
reply = r.json()
|
||||||
|
assert r.status_code == 200
|
||||||
assert reply == [{'kind': 'group', 'name': 'alphaflight', 'users': []}]
|
assert reply == [{'kind': 'group', 'name': 'alphaflight', 'users': []}]
|
||||||
|
|
||||||
|
r = await api_request(app, "groups?limit=0")
|
||||||
|
r.raise_for_status()
|
||||||
|
reply = r.json()
|
||||||
|
assert reply == []
|
||||||
|
|
||||||
|
|
||||||
@mark.group
|
@mark.group
|
||||||
async def test_add_multi_group(app):
|
async def test_add_multi_group(app):
|
||||||
@@ -1444,7 +1497,41 @@ async def test_group_get(app):
|
|||||||
r = await api_request(app, 'groups/alphaflight')
|
r = await api_request(app, 'groups/alphaflight')
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
reply = r.json()
|
reply = r.json()
|
||||||
assert reply == {'kind': 'group', 'name': 'alphaflight', 'users': ['sasquatch']}
|
assert reply == {
|
||||||
|
'kind': 'group',
|
||||||
|
'name': 'alphaflight',
|
||||||
|
'users': ['sasquatch'],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@mark.group
|
||||||
|
async def test_group_user_pagination(app):
|
||||||
|
group = orm.Group.find(app.db, name='betaflight')
|
||||||
|
user = add_user(app.db, app=app, name='bigfoot')
|
||||||
|
second_user = add_user(app.db, app=app, name='birdman')
|
||||||
|
group.users.append(user)
|
||||||
|
group.users.append(second_user)
|
||||||
|
app.db.commit()
|
||||||
|
|
||||||
|
# Test offset for pagination
|
||||||
|
r = await api_request(app, 'groups/betaflight?offset=1')
|
||||||
|
r.raise_for_status()
|
||||||
|
reply = r.json()
|
||||||
|
assert reply == {'kind': 'group', 'name': 'betaflight', 'users': ['birdman']}
|
||||||
|
|
||||||
|
r = await api_request(app, 'groups/betaflight?offset=10')
|
||||||
|
r.raise_for_status()
|
||||||
|
assert r.json() == {'kind': 'group', 'name': 'betaflight', 'users': []}
|
||||||
|
|
||||||
|
# Test limit for pagination
|
||||||
|
r = await api_request(app, 'groups/betaflight?limit=1')
|
||||||
|
r.raise_for_status()
|
||||||
|
reply = r.json()
|
||||||
|
assert reply == {'kind': 'group', 'name': 'betaflight', 'users': ['bigfoot']}
|
||||||
|
|
||||||
|
r = await api_request(app, 'groups/betaflight?limit=0')
|
||||||
|
r.raise_for_status()
|
||||||
|
assert r.json() == {'kind': 'group', 'name': 'betaflight', 'users': []}
|
||||||
|
|
||||||
|
|
||||||
@mark.group
|
@mark.group
|
||||||
|
Reference in New Issue
Block a user