Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
0
    def test_create_category_board_not_found(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_read_permissions(),
                ) as mocked_get_permissions, \
                patch.object(
                    CategoryService,
                    'create_category',
                    side_effect=BoardNotFoundException,
                ) as mocked_create_category:
            response = api_client.post('/api/v1/categories',
                                       data=payload,
                                       format='json')

        self.assertEqual(response.status_code, 400)
        expected_response = {
            'error_code': BoardNotFoundException.code,
            'error_message': BoardNotFoundException.message,
        }
        mocked_get_permissions.assert_called_with(
            board_id=payload['board_id'],
            user_id=user.id,
        )
        mocked_create_category.assert_called_with(
            board_id=payload['board_id'],
            name=payload['name'],
        )
        self.assertDictEqual(response.data, expected_response)
Beispiel #4
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)