Exemplo n.º 1
0
    def test_update_ticket_permission_denied(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {
            'title': 'Some Title',
            'body': 'Some Body',
            'due_date': '2021-01-01',
        }
        with patch.object(PermissionsService,
                          'get_ticket_permissions',
                          return_value=Permissions.with_read_permissions()
                          ) as mocked_get_ticket_permissions:
            response = api_client.patch('/api/v1/tickets/1',
                                        data=payload,
                                        format='json')

        self.assertEqual(response.status_code, 403)
        expected_response = {
            'error_code': PermissionDeniedException.code,
            'error_message': PermissionDeniedException.message,
        }
        mocked_get_ticket_permissions.assert_called_with(
            user_id=user.id,
            ticket_id=1,
        )
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 2
0
    def test_create_ticket(self):
        api_client = APIClient()
        user = UserFactory()
        payload = {
            'category_id': 1,
        }
        api_client.force_authenticate(user=user)

        ticket = TicketFactory()
        with \
                patch.object(
                    PermissionsService,
                    'get_category_permissions',
                    return_value=Permissions.with_mutate_permissions(),
                ) as mocked_get_permissions, \
                patch.object(TicketService, 'create_ticket', return_value=ticket) as mocked_create_ticket:
            response = api_client.post('/api/v1/tickets',
                                       data=payload,
                                       format='json')

        self.assertEqual(response.status_code, 201)
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            category_id=payload['category_id'],
        )
        mocked_create_ticket.assert_called_with(
            category_id=payload['category_id'], )
        expected_response = {
            'id': str(ticket.id),
            'category_id': str(ticket.category_id),
            'priority': ticket.priority,
        }
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 3
0
    def test_create_category_permission_denied(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {
            'board_id': 1,
            'name': 'category',
        }
        with \
                patch.object(
                    PermissionsService,
                    'get_board_permissions',
                    return_value=Permissions.with_no_permissions(),
                ) as mocked_get_permissions, \
                patch.object(CategoryService, 'create_category') as mocked_create_category:
            response = api_client.post('/api/v1/categories',
                                       data=payload,
                                       format='json')

        self.assertEqual(response.status_code, 403)
        expected_response = {
            'error_code': PermissionDeniedException.code,
            'error_message': PermissionDeniedException.message,
        }
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            board_id=payload['board_id'],
        )
        mocked_create_category.assert_not_called()
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 4
0
    def test_create_ticket_category_not_found(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {
            'category_id': 1,
        }
        with \
                patch.object(
                    PermissionsService,
                    'get_category_permissions',
                    return_value=Permissions.with_mutate_permissions(),
                ) as mocked_get_permissions, \
                patch.object(TicketService, 'create_ticket', side_effect=CategoryNotFoundException) \
                as mocked_create_ticket:
            response = api_client.post('/api/v1/tickets',
                                       data=payload,
                                       format='json')

        self.assertEqual(response.status_code, 400)
        expected_response = {
            'error_code': CategoryNotFoundException.code,
            'error_message': CategoryNotFoundException.message,
        }
        mocked_get_permissions.assert_called_with(
            category_id=payload['category_id'],
            user_id=user.id,
        )
        mocked_create_ticket.assert_called_with(
            category_id=payload['category_id'], )
        self.assertDictEqual(response.data, expected_response)
    def test_accept_or_decline_invite_already_a_member(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {'accept': True}
        with \
                patch.object(
                    PermissionsService,
                    'get_organization_invite_permissions',
                    return_value=Permissions.with_all_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    OrganizationInviteService,
                    'accept_or_decline_invite',
                    side_effect=OrganizationMembershipAlreadyExistsException
                ) as mocked_accept_or_decline_invite:
            response = api_client.patch(f'/api/v1/organization-invites/42', data=payload, format='json')

        self.assertEqual(response.status_code, 400)
        mocked_get_permissions.assert_called_with(
            organization_invite_id=42,
            user_id=user.id,
        )
        mocked_accept_or_decline_invite.assert_called_with(
            organization_invite_id=42,
            accept=payload['accept'],
        )
        expected_response = {
            'error_code': OrganizationMembershipAlreadyExistsException.code,
            'error_message': OrganizationMembershipAlreadyExistsException.message,
        }
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 6
0
    def test_delete_ticket_assignment_ticket_assignment_not_found(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        with \
                patch.object(
                    PermissionsService,
                    'get_ticket_assignment_permissions',
                    return_value=Permissions.with_all_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    TicketAssignmentService,
                    'delete_ticket_assignment',
                    side_effect=TicketAssignmentNotFoundException,
                ) as mocked_unassign_member:
            response = api_client.delete('/api/v1/ticket-assignments/1')

        self.assertEqual(response.status_code, 400)
        expected_response = {
            'error_code': TicketAssignmentNotFoundException.code,
            'error_message': TicketAssignmentNotFoundException.message,
        }
        mocked_get_permissions.assert_called_with(
            ticket_assignment_id=1,
            user_id=user.id,
        )
        mocked_unassign_member.assert_called_with(
            ticket_assignment_id=1,
        )
        self.assertDictEqual(response.data, expected_response)
    def test_create_invite_permission_denied(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {
            'organization_id': 1,
            'email': '*****@*****.**',
            'message': 'message',
        }
        with \
                patch.object(
                    PermissionsService,
                    'get_organization_permissions',
                    return_value=Permissions.with_no_permissions(),
                ) as mocked_get_permissions, \
                patch.object(OrganizationInviteService, 'create_organization_invite') as mocked_send_invite:
            response = api_client.post('/api/v1/organization-invites', data=payload, format='json')

        self.assertEqual(response.status_code, 403)
        expected_response = {
            'error_code': PermissionDeniedException.code,
            'error_message': PermissionDeniedException.message,
        }
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            organization_id=payload['organization_id'],
        )
        mocked_send_invite.assert_not_called()
        self.assertDictEqual(response.data, expected_response)
    def test_create_board_membership_permission_denied(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        with \
                patch.object(
                    PermissionsService,
                    'get_board_membership_permissions',
                    return_value=Permissions.with_mutate_permissions(),
                ) as mocked_get_permissions, \
                patch.object(BoardMembershipService, 'delete_board_membership') as mocked_delete_member:
            response = api_client.delete('/api/v1/board-memberships/1')

        self.assertEqual(response.status_code, 403)
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            board_membership_id=1,
        )
        mocked_delete_member.assert_not_called()
        expected_response = {
            'error_code': PermissionDeniedException.code,
            'error_message': PermissionDeniedException.message,
        }
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 9
0
    def test_create_board_permission_denied(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)
        payload = {
            'name': 'Main Board',
            'organization_id': 1,
        }

        with \
                patch.object(
                    PermissionsService,
                    'get_organization_permissions',
                    return_value=Permissions.with_no_permissions(),
                ) as mocked_get_permissions, \
                patch.object(BoardService, 'create_board') as mocked_create_board:
            response = api_client.post('/api/v1/boards',
                                       data=payload,
                                       format='json')

        self.assertEqual(response.status_code, 403)
        mocked_create_board.assert_not_called()
        mocked_get_permissions.assert_called_with(
            user_id=user.id, organization_id=payload['organization_id'])
        expected_response = {
            'error_code': PermissionDeniedException.code,
            'error_message': PermissionDeniedException.message,
        }
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 10
0
    def test_create_ticket_assignment_permission_denied(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {
            'ticket_id': 1,
            'board_membership_id': 1,
        }
        with \
                patch.object(
                    PermissionsService,
                    'get_ticket_permissions',
                    return_value=Permissions.with_read_permissions(),
                ) as mocked_get_permissions, \
                patch.object(TicketAssignmentService, 'create_ticket_assignment') as mocked_assign_member:
            response = api_client.post('/api/v1/ticket-assignments', data=payload, format='json')

        self.assertEqual(response.status_code, 403)
        expected_response = {
            'error_code': PermissionDeniedException.code,
            'error_message': PermissionDeniedException.message,
        }
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            ticket_id=payload['ticket_id'],
        )
        mocked_assign_member.assert_not_called()
        self.assertDictEqual(response.data, expected_response)
    def test_accept_or_decline_invite_permission_denied(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {'accept': True}
        with \
                patch.object(
                    PermissionsService,
                    'get_organization_invite_permissions',
                    return_value=Permissions.with_no_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    OrganizationInviteService,
                    'accept_or_decline_invite',
                ) as mocked_accept_or_decline_invite:
            response = api_client.patch('/api/v1/organization-invites/1', data=payload, format='json')

        self.assertEqual(response.status_code, 403)
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            organization_invite_id=1,
        )
        mocked_accept_or_decline_invite.assert_not_called()
        expected_response = {
            'error_code': PermissionDeniedException.code,
            'error_message': PermissionDeniedException.message,
        }
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 12
0
    def test_update_ticket(self):
        api_client = APIClient()
        user = UserFactory()
        payload = {
            'title': 'Some Title',
            'body': 'Some Body',
            'due_date': '2021-01-01',
        }
        api_client.force_authenticate(user=user)

        ticket = TicketFactory()
        with \
                patch.object(
                    PermissionsService,
                    'get_ticket_permissions',
                    return_value=Permissions.with_mutate_permissions(),
                ) as mocked_get_ticket_permissions, \
                patch.object(TicketService, 'update_ticket', return_value=ticket) as mocked_update_ticket:
            response = api_client.patch('/api/v1/tickets/1',
                                        data=payload,
                                        format='json')

        self.assertEqual(response.status_code, 200)
        mocked_get_ticket_permissions.assert_called_with(
            user_id=user.id,
            ticket_id=1,
        )
        mocked_update_ticket.assert_called_with(ticket_id=1,
                                                validated_data={
                                                    'title':
                                                    payload['title'],
                                                    'body':
                                                    payload['body'],
                                                    'due_date':
                                                    date.fromisoformat(
                                                        payload['due_date']),
                                                })
        expected_response = {
            'id': str(ticket.id),
            'title': ticket.title,
            'body': ticket.body,
            'due_date': ticket.due_date.isoformat(),
            'priority': ticket.priority,
            'category_id': str(ticket.category_id),
        }
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 13
0
    def test_update_ticket_ticket_not_found(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {
            'title': 'Some Title',
            'body': 'Some Body',
            'due_date': '2021-01-01',
        }
        with \
                patch.object(
                    PermissionsService,
                    'get_ticket_permissions',
                    return_value=Permissions.with_mutate_permissions(),
                ) as mocked_get_ticket_permissions, \
                patch.object(
                    TicketService,
                    'update_ticket',
                    side_effect=TicketNotFoundException
                ) as mocked_update_ticket:
            response = api_client.patch('/api/v1/tickets/1',
                                        data=payload,
                                        format='json')

        self.assertEqual(response.status_code, 400)
        expected_response = {
            'error_code': TicketNotFoundException.code,
            'error_message': TicketNotFoundException.message,
        }
        mocked_get_ticket_permissions.assert_called_with(
            user_id=user.id,
            ticket_id=1,
        )
        mocked_update_ticket.assert_called_with(ticket_id=1,
                                                validated_data={
                                                    'title':
                                                    payload['title'],
                                                    'body':
                                                    payload['body'],
                                                    'due_date':
                                                    date.fromisoformat(
                                                        payload['due_date']),
                                                })
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 14
0
    def test_create_board(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        board = BoardFactory()
        payload = {
            'name': 'Main Board',
            'organization_id': board.organization_id,
        }
        with  \
                patch.object(
                    PermissionsService,
                    'get_organization_permissions',
                    return_value=Permissions.with_all_permissions()
                ) as mocked_get_permissions, \
                patch.object(BoardService, 'create_board', return_value=board) as mocked_create_board, \
                patch.object(CategoryService, 'create_category') as mocked_create_category:
            response = api_client.post('/api/v1/boards',
                                       data=payload,
                                       format='json')

        self.assertEqual(response.status_code, 201)
        mocked_get_permissions.assert_called_with(
            organization_id=board.organization_id,
            user_id=user.id,
        )
        mocked_create_board.assert_called_with(
            name=payload['name'],
            organization_id=payload['organization_id'],
        )
        mocked_create_category.assert_called_with(
            name=CategoryService.NOT_SORTED,
            board_id=board.id,
        )
        self.assertDictEqual(
            response.data,
            {
                'id': str(board.id),
                'name': board.name,
                'organization_id': str(board.organization_id)
            },
        )
Exemplo n.º 15
0
    def test_create_board_membership(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)
        board_membership = BoardMembershipFactory()

        payload = {
            'board_id': board_membership.board_id,
            'organization_id': 56,
            'organization_membership_id': 42,
        }

        with \
                patch.object(
                    PermissionsService,
                    'get_board_permissions',
                    return_value=Permissions.with_mutate_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    BoardMembershipService,
                    'create_board_membership',
                    return_value=board_membership,
                ) as mocked_add_member:
            response = api_client.post('/api/v1/board-memberships', data=payload, format='json')

        self.assertEqual(response.status_code, 201)
        mocked_get_permissions.assert_called_with(
            board_id=payload['board_id'],
            user_id=user.id,
        )
        mocked_add_member.assert_called_with(
            board_id=payload['board_id'],
            organization_membership_id=payload['organization_membership_id'],
        )
        self.assertDictEqual(
            response.data,
            {
                'id': str(board_membership.id),
                'board_id': str(board_membership.board_id),
                'organization_membership_id': str(board_membership.organization_membership_id),
            },
        )
Exemplo n.º 16
0
    def test_delete_board_membership(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        with \
                patch.object(
                    PermissionsService,
                    'get_board_membership_permissions',
                    return_value=Permissions.with_all_permissions(),
                ) as mocked_get_permissions, \
                patch.object(BoardMembershipService, 'delete_board_membership') as mocked_delete_member:
            response = api_client.delete('/api/v1/board-memberships/42')

        self.assertEqual(response.status_code, 204)
        mocked_get_permissions.assert_called_with(
            board_membership_id=42,
            user_id=user.id,
        )
        mocked_delete_member.assert_called_with(board_membership_id=42)
    def test_create_invite(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user)
        invite = OrganizationInviteFactory()

        payload = {
            'organization_id': 42,
            'email': invite.user.email,
            'message': 'message',
        }
        with \
                patch.object(
                    PermissionsService,
                    'get_organization_permissions',
                    return_value=Permissions.with_all_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    OrganizationInviteService,
                    'create_organization_invite',
                    return_value=invite,
                ) as mocked_send_invite:
            response = api_client.post('/api/v1/organization-invites', data=payload, format='json')

        self.assertEqual(response.status_code, 201)
        mocked_get_permissions.assert_called_with(
            organization_id=payload['organization_id'],
            user_id=user.id,
        )
        mocked_send_invite.assert_called_with(
            organization_id=payload['organization_id'],
            email=payload['email'],
            message=payload['message']
        )
        expected_response = {
            'id': str(invite.id),
            'user_id': str(invite.user_id),
            'organization_id': str(invite.organization_id),
            'message': invite.message,
        }
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 18
0
    def test_delete_ticket_assignment(self):
        api_client = APIClient()
        user = UserFactory()
        api_client.force_authenticate(user=user)

        with \
                patch.object(
                    PermissionsService,
                    'get_ticket_assignment_permissions',
                    return_value=Permissions.with_all_permissions(),
                ) as mocked_get_permissions, \
                patch.object(TicketAssignmentService, 'delete_ticket_assignment') as mocked_unassign_member:
            response = api_client.delete('/api/v1/ticket-assignments/1',)

        self.assertEqual(response.status_code, 204)
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            ticket_assignment_id=1,
        )
        mocked_unassign_member.assert_called_with(
            ticket_assignment_id=1,
        )
Exemplo n.º 19
0
    def test_create_board_membership_already_exists(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {
            'board_id': 1,
            'organization_id': 2,
            'organization_membership_id': 3,
        }

        with \
                patch.object(
                    PermissionsService,
                    'get_board_permissions',
                    return_value=Permissions.with_mutate_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    BoardMembershipService,
                    'create_board_membership',
                    side_effect=BoardMembershipAlreadyExistsException,
                ) as mocked_add_member:
            response = api_client.post('/api/v1/board-memberships', data=payload, format='json')

        self.assertEqual(response.status_code, 400)
        mocked_get_permissions.assert_called_with(
            board_id=payload['board_id'],
            user_id=user.id,
        )
        mocked_add_member.assert_called_with(
            board_id=payload['board_id'],
            organization_membership_id=payload['organization_membership_id'],
        )
        expected_response = {
            'error_code': BoardMembershipAlreadyExistsException.code,
            'error_message': BoardMembershipAlreadyExistsException.message,
        }
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 20
0
    def test_create_ticket_assignment(self):
        api_client = APIClient()
        user = UserFactory()
        payload = {
            'ticket_id': 1,
            'board_membership_id': 1,
        }
        api_client.force_authenticate(user=user)

        ticket_assignment = TicketAssignmentFactory()
        with \
                patch.object(
                    PermissionsService,
                    'get_ticket_permissions',
                    return_value=Permissions.with_mutate_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    TicketAssignmentService,
                    'create_ticket_assignment',
                    return_value=ticket_assignment,
                ) as mocked_assign_member:
            response = api_client.post('/api/v1/ticket-assignments', data=payload, format='json')

        self.assertEqual(response.status_code, 201)
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            ticket_id=payload['ticket_id'],
        )
        mocked_assign_member.assert_called_with(
            ticket_id=payload['ticket_id'],
            board_membership_id=payload['board_membership_id'],
        )
        expected_response = {
            'id': str(ticket_assignment.id),
            'ticket_id': str(ticket_assignment.ticket_id),
            'assignee_id': str(ticket_assignment.assignee_id),
        }
        self.assertDictEqual(response.data, expected_response)
    def test_create_invite_already_exists(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {
            'organization_id': 42,
            'email': user.email,
            'message': 'message',
        }
        with \
                patch.object(
                    PermissionsService,
                    'get_organization_permissions',
                    return_value=Permissions.with_all_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    OrganizationInviteService,
                    'create_organization_invite',
                    side_effect=OrganizationInviteAlreadyExistsException,
                ) as mocked_send_invite:
            response = api_client.post('/api/v1/organization-invites', data=payload, format='json')

        self.assertEqual(response.status_code, 400)
        expected_response = {
            'error_code': OrganizationInviteAlreadyExistsException.code,
            'error_message': OrganizationInviteAlreadyExistsException.message,
        }
        mocked_get_permissions.assert_called_with(
            organization_id=payload['organization_id'],
            user_id=user.id,
        )
        mocked_send_invite.assert_called_with(
            organization_id=payload['organization_id'],
            email=payload['email'],
            message=payload['message'],
        )
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 22
0
    def test_create_comment(self):
        api_client = APIClient()
        user = UserFactory()
        payload = {
            'ticket_id': 1,
            'message': 'test_message',
        }
        api_client.force_authenticate(user=user)

        comment = CommentFactory()
        with \
                patch.object(
                    PermissionsService,
                    'get_ticket_permissions',
                    return_value=Permissions.with_mutate_permissions()
                ) as mocked_get_permissions, \
                patch.object(CommentService, 'create_comment', return_value=comment) as mocked_create_comment:
            response = api_client.post(reverse('tickets:comments'), data=payload, format='json')

        self.assertEqual(response.status_code, 201)
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            ticket_id=payload['ticket_id'],
        )
        mocked_create_comment.assert_called_with(
            user_id=user.id,
            ticket_id=payload['ticket_id'],
            message=payload['message'],
        )
        expected_response = {
            'id': str(comment.id),
            'ticket_id': str(comment.ticket_id),
            'author_id': str(comment.author_id),
            'message': str(comment.message),
            'added_at': comment.added_at.strftime('%Y-%m-%dT%H:%M:%S.%f%z'),
        }
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 23
0
    def test_create_comment_board_membership_not_found(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {
            'ticket_id': 1,
            'message': 'test_message',
        }
        with \
                patch.object(
                    PermissionsService,
                    'get_ticket_permissions',
                    return_value=Permissions.with_mutate_permissions()
                ) as mocked_get_permissions, \
                patch.object(
                    CommentService,
                    'create_comment',
                    side_effect=BoardMembershipNotFoundException,
                ) as mocked_create_comment:
            response = api_client.post(reverse('tickets:comments'), data=payload, format='json')

        self.assertEqual(response.status_code, 400)
        expected_response = {
            'error_code': BoardMembershipNotFoundException.code,
            'error_message': BoardMembershipNotFoundException.message,
        }
        mocked_get_permissions.assert_called_with(
            ticket_id=payload['ticket_id'],
            user_id=user.id,
        )
        mocked_create_comment.assert_called_with(
            ticket_id=payload['ticket_id'],
            user_id=user.id,
            message=payload['message'],
        )
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 24
0
    def test_create_category(self):
        api_client = APIClient()
        user = UserFactory()
        payload = {
            'board_id': 1,
            'name': 'category',
        }
        api_client.force_authenticate(user=user)

        category = CategoryFactory()
        with \
                patch.object(
                    PermissionsService,
                    'get_board_permissions',
                    return_value=Permissions.with_read_permissions(),
                ) as mocked_get_permissions, \
                patch.object(CategoryService, 'create_category', return_value=category) as mocked_create_category:
            response = api_client.post('/api/v1/categories',
                                       data=payload,
                                       format='json')

        self.assertEqual(response.status_code, 201)
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            board_id=payload['board_id'],
        )
        mocked_create_category.assert_called_with(
            board_id=payload['board_id'],
            name=payload['name'],
        )
        expected_response = {
            'id': str(category.id),
            'name': category.name,
            'board_id': str(category.board_id),
        }
        self.assertDictEqual(response.data, expected_response)
Exemplo n.º 25
0
    def test_create_board_already_exists(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)
        payload = {
            'name': 'Main Board',
            'organization_id': 42,
        }

        with \
                patch.object(
                    PermissionsService,
                    'get_organization_permissions',
                    return_value=Permissions.with_all_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    BoardService,
                    'create_board',
                    side_effect=BoardAlreadyExistsException,
                ) as mocked_create_board:
            response = api_client.post('/api/v1/boards',
                                       data=payload,
                                       format='json')

        self.assertEqual(response.status_code, 400)
        mocked_create_board.assert_called_with(
            name=payload['name'], organization_id=payload['organization_id'])
        mocked_get_permissions.assert_called_with(
            organization_id=payload['organization_id'],
            user_id=user.id,
        )
        expected_response = {
            'error_code': BoardAlreadyExistsException.code,
            'error_message': BoardAlreadyExistsException.message,
        }
        self.assertDictEqual(response.data, expected_response)
    def test_accept_or_decline_invite(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        payload = {'accept': True}
        with \
                patch.object(
                    PermissionsService,
                    'get_organization_invite_permissions',
                    return_value=Permissions.with_all_permissions(),
                ) as mocked_get_permissions, \
                patch.object(OrganizationInviteService, 'accept_or_decline_invite') as mocked_accept_or_decline_invite:
            response = api_client.patch(f'/api/v1/organization-invites/42', data=payload, format='json')

        self.assertEqual(response.status_code, 204)
        mocked_get_permissions.assert_called_with(
            organization_invite_id=42,
            user_id=user.id,
        )
        mocked_accept_or_decline_invite.assert_called_with(
            organization_invite_id=42,
            accept=payload['accept'],
        )