Example #1
0
    def perform(self, account_request_object):
        """Accept an Account Request

        Args:

            account_request_object: account_request
        """
        account_request_api.accept(account_request_object)
Example #2
0
    def test_account_request_accept_raise_ApiError_if_user_does_not_exist(
            self, mock_get_user_by_username, mock_delete):
        # Arrange
        mock_get_user_by_username.side_effect = ObjectDoesNotExist()

        # Act # Assert
        with self.assertRaises(ApiError):
            account_request_api.accept(self.account_request)
Example #3
0
def accept(request):
    """
        Accept an account request

        Parameters:
            request (HttpRequest): request

        Returns:
            Response object
    """
    try:
        # Get parameters
        request_id = request.DATA['requestid']
        account_request_from_api = account_request_api.get(request_id)
        try:
            user_request = account_request_api.accept(account_request_from_api,
                                                      send_mail=False)
        except Exception as api_exception:
            content = {'message': api_exception.message}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)

        # Serialize the request
        serializer = AccountRequestSerializer(user_request)

        if serializer.is_valid():
            return Response(serializer.data, status=status.HTTP_200_OK)
        else:
            content = {'message': 'Serialization failed'}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)

    except Exception as e:
        content = {'message': 'Expected parameters not provided.'}
        logger.exception(e.message)
        return Response(content, status=status.HTTP_400_BAD_REQUEST)
Example #4
0
def accept_request(request):
    """
    Accepts a request and creates the user account
    :param request:
    :return:
    """
    try:
        request_id = request.POST['requestid']
        account_request_from_api = account_request_api.get(request_id)
        account_request_api.accept(account_request_from_api)
        message = "Request Accepted"
    except main_exceptions.ApiError as error:
        raise exceptions.WebsiteAjaxError(error.message)
    except Exception as exception:
        raise exceptions.WebsiteAjaxError(exception.message)

    return HttpResponse(json.dumps({"message": message}),
                        content_type='application/json')
Example #5
0
    def test_account_request_accept_return_user(self, mock_get_by_username,
                                                mock_create_and_save,
                                                mock_delete):
        # Arrange
        mock_user = Mock(spec=User)
        mock_user.id = 1
        mock_get_by_username.return_value = mock_user
        mock_create_and_save.return_value = mock_user
        mock_delete.return_value = None

        # Act
        result = account_request_api.accept(self.account_request)

        #  Assert
        self.assertIsInstance(result, User)