|
1
|
|
|
import pytest |
|
2
|
|
|
from factory.django import DjangoModelFactory |
|
3
|
|
|
from rest_framework import status |
|
4
|
|
|
from rest_framework.reverse import reverse |
|
5
|
|
|
|
|
6
|
|
|
from tests.factories import ( |
|
7
|
|
|
BoardFactory as board_factory, |
|
8
|
|
|
CategoryFactory as category_factory, |
|
9
|
|
|
GoalFactory as goal_factory, |
|
10
|
|
|
CommentFactory as comment_factory |
|
11
|
|
|
) |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
@pytest.mark.django_db() |
|
15
|
|
|
@pytest.mark.parametrize( |
|
16
|
|
|
'factory, url', [ |
|
17
|
|
|
(board_factory, reverse('goals:board-list')), |
|
18
|
|
|
(category_factory, reverse('goals:category-list')), |
|
19
|
|
|
(comment_factory, reverse('goals:comment-list')) |
|
20
|
|
|
], |
|
21
|
|
|
ids=['board-list', 'category-list', 'comment-list'] |
|
22
|
|
|
) |
|
23
|
|
|
def test_pagination(factory: DjangoModelFactory, url: str, auth_client, user): |
|
24
|
|
|
"""Тест на эндпоинты GET: {basename}-list |
|
25
|
|
|
|
|
26
|
|
|
Производит проверку функционирования пагинации |
|
27
|
|
|
""" |
|
28
|
|
|
if factory == board_factory: |
|
29
|
|
|
factory.create_batch(size=10, with_owner=user) |
|
30
|
|
|
|
|
31
|
|
|
elif factory == category_factory: |
|
32
|
|
|
board = board_factory.create(with_owner=user) |
|
33
|
|
|
factory.create_batch(size=10, board=board) |
|
34
|
|
|
|
|
35
|
|
|
elif factory == comment_factory: |
|
36
|
|
|
board = board_factory.create(with_owner=user) |
|
37
|
|
|
category = category_factory.create(board=board) |
|
38
|
|
|
goal = goal_factory.create(category=category) |
|
39
|
|
|
factory.create_batch(size=10, goal=goal, user=user) |
|
40
|
|
|
|
|
41
|
|
|
limit_response = auth_client.get(url, {'limit': 3}) |
|
42
|
|
|
assert limit_response.status_code == status.HTTP_200_OK |
|
43
|
|
|
assert limit_response.json()['count'] == 10 |
|
44
|
|
|
assert len(limit_response.json()['results']) == 3 |
|
45
|
|
|
|
|
46
|
|
|
offset_response = auth_client.get(url, {'limit': 100, 'offset': 8}) |
|
47
|
|
|
assert offset_response.status_code == status.HTTP_200_OK |
|
48
|
|
|
assert offset_response.json()['count'] == 10 |
|
49
|
|
|
assert len(offset_response.json()['results']) == 2 |
|
50
|
|
|
|