def call_post_request(self,
                       headers=None,
                       endpoint=None,
                       fullstring=None,
                       data=None,
                       files=None,
                       cookies=None,
                       timeout=None):
     """ Generate a POST Request. This Keyword is basically a wrapper for post_request from the RequestsLibrary.\n
         headers: (dictionary) The headers to be sent as part of the request.\n
         endpoint: (string) The string that identifies the url endpoint of the App that receives API requests.\n
         fullstring: (string) A string that contains the rest of the url that identifies a specific API/Webservice
         along with any query parameters.\n
         timeout: (float) Time in seconds for the api to respond\n
         data: (json) The JSON object to be sent on the body of the request to be used by the specific Web service.\n
         files: (json) A JSON object that sends in the body of the request to be used by the specific Web service.\n
         return: (response object) Returns the request response object, which includes headers, content, etc.
     """
     if self.suppress_warnings:
         urllib3.disable_warnings(InsecureRequestWarning)
     session = requests_lib.create_session("postapi",
                                           endpoint,
                                           headers,
                                           cookies=cookies,
                                           timeout=timeout)
     data = utils.format_data_according_to_header(session, data, headers)
     resp = requests_lib.post_on_session("postapi",
                                         fullstring,
                                         data,
                                         files=files,
                                         timeout=timeout,
                                         expected_status='any')
     return _convert_resp_to_dict(resp)
Example #2
0
    def post_request(
            self,
            alias,
            uri,
            data=None,
            json=None,
            params=None,
            headers=None,
            files=None,
            allow_redirects=None,
            timeout=None,
            log_options=None,
    ):
        """ Send a POST request on the session object found using the
        given `alias`

        ``alias`` that will be used to identify the Session object in the cache

        ``uri`` to send the POST request to

        ``data`` a dictionary of key-value pairs that will be urlencoded
               and sent as POST data
               or binary data that is sent as the raw body content
               or passed as such for multipart form data if ``files`` is also defined
               or file descriptor retrieved by Get File For Streaming Upload

        ``json`` a value that will be json encoded
               and sent as POST data if files or data is not specified

        ``params`` url parameters to append to the uri

        ``headers`` a dictionary of headers to use with the request

        ``files`` a dictionary of file names containing file data to POST to the server

        ``allow_redirects`` Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.

        ``timeout`` connection timeout
        """
        session = self._cache.switch(alias)
        if not files:
            data = utils.format_data_according_to_header(session, data, headers)
        redir = True if allow_redirects is None else allow_redirects

        response = self._common_request(
            "post",
            session,
            uri,
            data=data,
            json=json,
            params=params,
            files=files,
            headers=headers,
            allow_redirects=redir,
            timeout=timeout,
            log_options=log_options,
        )

        return response
Example #3
0
    def patch_request(self,
                      alias,
                      uri,
                      data=None,
                      json=None,
                      params=None,
                      headers=None,
                      files=None,
                      allow_redirects=None,
                      timeout=None):
        """ Send a PATCH request on the session object found using the
        given `alias`

        ``alias`` that will be used to identify the Session object in the cache

        ``uri`` to send the PATCH request to

        ``data`` a dictionary of key-value pairs that will be urlencoded
               and sent as PATCH data
               or binary data that is sent as the raw body content
               or file descriptor retrieved by Get File For Streaming Upload

        ``json`` a value that will be json encoded
               and sent as PATCH data if data is not specified

        ``headers`` a dictionary of headers to use with the request

        ``files`` a dictionary of file names containing file data to PATCH to the server

        ``allow_redirects`` Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.

        ``params`` url parameters to append to the uri

        ``timeout`` connection timeout
        """
        session = self._cache.switch(alias)
        data = utils.format_data_according_to_header(session, data, headers)
        # XXX workaround to restore library default behaviour. Not needed in new keywords
        redir = True if allow_redirects is None else allow_redirects

        response = self._common_request("patch",
                                        session,
                                        uri,
                                        data=data,
                                        json=json,
                                        params=params,
                                        files=files,
                                        headers=headers,
                                        allow_redirects=redir,
                                        timeout=timeout)

        return response
    def put_request(
            self,
            alias,
            uri,
            data=None,
            json=None,
            params=None,
            files=None,
            headers=None,
            allow_redirects=None,
            timeout=None):
        """ Send a PUT request on the session object found using the
        given `alias`

        ``alias`` that will be used to identify the Session object in the cache

        ``uri`` to send the PUT request to

        ``data`` a dictionary of key-value pairs that will be urlencoded
               and sent as PUT data
               or binary data that is sent as the raw body content

        ``json`` a value that will be json encoded
               and sent as PUT data if data is not specified

        ``headers`` a dictionary of headers to use with the request

        ``allow_redirects`` Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.

        ``params`` url parameters to append to the uri

        ``timeout`` connection timeout
        """
        session = self._cache.switch(alias)
        data = utils.format_data_according_to_header(session, data, headers)
        redir = True if allow_redirects is None else allow_redirects

        response = self._common_request(
            "put",
            session,
            uri,
            data=data,
            json=json,
            params=params,
            files=files,
            headers=headers,
            allow_redirects=redir,
            timeout=timeout)

        return response
Example #5
0
    def delete_request(
            self,
            alias,
            uri,
            data=None,
            json=None,
            params=None,
            headers=None,
            allow_redirects=None,
            timeout=None,
            log_options=None,
    ):
        """ Send a DELETE request on the session object found using the
        given `alias`

        ``alias`` that will be used to identify the Session object in the cache

        ``uri`` to send the DELETE request to

        ``json`` a value that will be json encoded
               and sent as request data if data is not specified

        ``headers`` a dictionary of headers to use with the request

        ``allow_redirects`` Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.

        ``timeout`` connection timeout
        """
        session = self._cache.switch(alias)
        data = utils.format_data_according_to_header(session, data, headers)
        redir = True if allow_redirects is None else allow_redirects

        response = self._common_request(
            "delete",
            session,
            uri,
            data=data,
            json=json,
            params=params,
            headers=headers,
            allow_redirects=redir,
            timeout=timeout,
            log_options=log_options,
        )

        return response