0001-api-add-page-size-parameter-to-user-s-API-54514.patch
src/authentic2/api_views.py | ||
---|---|---|
717 | 717 |
return queryset |
718 | 718 | |
719 | 719 | |
720 |
class UsersAPIPagination(pagination.CursorPagination): |
|
721 |
page_size_query_param = 'limit' |
|
722 |
max_page_size = 100 |
|
723 | ||
724 | ||
720 | 725 |
class UsersAPI(api_mixins.GetOrCreateMixinView, HookMixin, ExceptionHandlerMixin, ModelViewSet): |
721 | 726 |
queryset = User.objects.all() |
722 | 727 |
ordering_fields = ['username', 'first_name', 'last_name', 'modified', 'date_joined'] |
... | ... | |
730 | 735 |
filter_class = UsersFilter |
731 | 736 |
filterset_class = UsersFilter |
732 | 737 |
filter_backends = [FreeTextSearchFilter] + api_settings.DEFAULT_FILTER_BACKENDS |
733 |
pagination_class = pagination.CursorPagination
|
|
738 |
pagination_class = UsersAPIPagination
|
|
734 | 739 | |
735 | 740 |
@property |
736 | 741 |
def ordering(self): |
tests/test_api.py | ||
---|---|---|
2544 | 2544 |
app.put_json( |
2545 | 2545 |
'/api/users/find_duplicates/', params={'first_name': 'Eleonore', 'last_name': 'aeiou'}, status=405 |
2546 | 2546 |
) |
2547 | ||
2548 | ||
2549 |
def test_users_page_size(app, admin): |
|
2550 |
app.authorization = ('Basic', (admin.username, admin.username)) |
|
2551 | ||
2552 |
User.objects.create() |
|
2553 | ||
2554 |
resp = app.get('/api/users/') |
|
2555 |
assert len(resp.json['results']) == 2 |
|
2556 | ||
2557 |
resp = app.get('/api/users/?limit=1') |
|
2558 |
assert len(resp.json['results']) == 1 |
|
2547 |
- |