Exemple #1
0
    def test_delete_ticket_assignment_permission_denied(self):
        user = UserFactory()
        api_client = APIClient()
        api_client.force_authenticate(user=user)

        with \
                patch.object(
                    PermissionsService,
                    'get_ticket_assignment_permissions',
                    return_value=Permissions.with_mutate_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, 403)
        expected_response = {
            'error_code': PermissionDeniedException.code,
            'error_message': PermissionDeniedException.message,
        }
        mocked_get_permissions.assert_called_with(
            user_id=user.id,
            ticket_assignment_id=1,
        )
        mocked_unassign_member.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)
Exemple #3
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)
Exemple #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)
Exemple #5
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)
Exemple #6
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)
    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),
            },
        )
Exemple #8
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_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)
Exemple #10
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)
Exemple #11
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)
Exemple #12
0
    def test_create_ticket_assignment_already_assigned(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_mutate_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    TicketAssignmentService,
                    'create_ticket_assignment',
                    side_effect=TicketAssignmentAlreadyExistsException,
                ) as mocked_assign_member:
            response = api_client.post('/api/v1/ticket-assignments', data=payload, format='json')

        self.assertEqual(response.status_code, 400)
        expected_response = {
            'error_code': TicketAssignmentAlreadyExistsException.code,
            'error_message': TicketAssignmentAlreadyExistsException.message,
        }
        mocked_get_permissions.assert_called_with(
            ticket_id=payload['ticket_id'],
            user_id=user.id,
        )
        mocked_assign_member.assert_called_with(
            ticket_id=payload['ticket_id'],
            board_membership_id=payload['board_membership_id'],
        )
        self.assertDictEqual(response.data, expected_response)