TestBoardCreate.test_creates_board_participant()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
rs 9.95
c 0
b 0
f 0
cc 1
nop 4
1
import pytest
2
from django.urls import reverse
3
from rest_framework import status
4
5
from tests.utils import BaseTestCase
6
from goals.models import Board, BoardParticipant
7
8
9
@pytest.mark.django_db()
10
class TestBoardCreate(BaseTestCase):
11
    url = reverse('goals:board-create')
12
13
    def test_auth_required(self, client, faker):
14
        """Тест на эндпоинт POST: /goals/board/create
15
16
        Производит проверку требований аутентификации.
17
        """
18
        response = client.post(self.url, data=faker.pydict(1))
19
        assert response.status_code == status.HTTP_403_FORBIDDEN
20
21
    def test_failed_to_create_deleted_board(self, auth_client, faker):
22
        """Тест на эндпоинт POST: /goals/board/create
23
24
        Производит проверку отсутствия возможности создать доску со статусом 'is_deleted': True
25
        """
26
        response = auth_client.post(self.url, data={
27
            'title': faker.sentence(),
28
            'is_deleted': True
29
        })
30
        assert response.status_code == status.HTTP_201_CREATED
31
        new_board = Board.objects.last()
32
        assert not new_board.is_deleted
33
34
    def test_creates_board_participant(self, auth_client, user, faker):
35
        """Тест на эндпоинт POST: /goals/board/create
36
37
        Производит проверку факта создания владельца доски при создании доски
38
        """
39
        response = auth_client.post(self.url, data={
40
            'title': faker.sentence(),
41
        })
42
        assert response.status_code == status.HTTP_201_CREATED
43
        new_board = Board.objects.last()
44
        participants = new_board.participants.all()
45
        assert len(participants) == 1
46
        assert participants[0].user == user
47
        assert participants[0].role == BoardParticipant.Role.owner
48
49
    def test_success(self, auth_client, settings):
50
        """Тест на эндпоинт POST: /goals/board/create
51
52
        Производит проверку корректности структуры ответа при успешном создании доски.
53
        """
54
        response = auth_client.post(self.url, data={
55
            'title': 'Board Title',
56
        })
57
        assert response.status_code == status.HTTP_201_CREATED
58
        new_board = Board.objects.last()
59
        assert response.json() == {
60
            'id': new_board.id,
61
            'created': self.datetime_to_str(new_board.created),
62
            'updated': self.datetime_to_str(new_board.updated),
63
            'title': 'Board Title',
64
            'is_deleted': False
65
        }
66