Exemplo n.º 1
0
    def test_put(self):
        # PUT something for the first time
        response = http(r"""PUT /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw
Content-Length: 20
Content-Type: text/plain

This is just a test.""")

        self.assertEquals(response.getStatus(), 201)
        self.assertEquals(response.getHeader("Location"),
                          "http://localhost/testfile.txt")

        response = http(r"""GET /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw""")
        self.assertEquals(response.getBody(), "This is just a test.")

        # now modify it
        response = http(r"""PUT /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw
Content-Length: 23
Content-Type: text/plain

And now it is modified.""")
        self.assertEquals(response.getStatus(), 200)
        self.assertEquals(response.getBody(), "")

        response = http(r"""GET /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw""")
        self.assertEquals(response.getBody(), "And now it is modified.")
    def test_put(self):
        # PUT something for the first time
        response = http(r"""PUT /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw
Content-Length: 20
Content-Type: text/plain

This is just a test.""")

        self.assertEquals(response.getStatus(), 201)
        self.assertEquals(response.getHeader("Location"),
                          "http://localhost/testfile.txt")

        response = http(r"""GET /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw""")
        self.assertEquals(response.getBody(), "This is just a test.")

        # now modify it
        response = http(r"""PUT /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw
Content-Length: 23
Content-Type: text/plain

And now it is modified.""")
        self.assertEquals(response.getStatus(), 200)
        self.assertEquals(response.getBody(), "")

        response = http(r"""GET /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw""")
        self.assertEquals(response.getBody(), "And now it is modified.")
 def _http(query_str, *args, **kwargs):
     # Strip leading \n
     query_str = query_str.lstrip()
     if not isinstance(query_str, bytes):
         query_str = query_str.encode("ascii")
     response = http(wsgi_app, query_str, *args, **kwargs)
     return response
 def _http(query_str, *args, **kwargs):
     wsgi_app = AppExceptionLayer.make_wsgi_app()
     # Strip leading \n
     query_str = query_str.lstrip()
     kwargs.setdefault('handle_errors', True)
     if not isinstance(query_str, bytes):
         query_str = query_str.encode("utf-8")
     return http(wsgi_app, query_str, *args, **kwargs)
Exemplo n.º 5
0
def http_call(method, path, data=None, **kw):
    """Function to help make RESTful calls.

    method - HTTP method to use
    path - testbrowser style path
    data - (body) data to submit
    kw - any request parameters
    """

    if path.startswith('http://localhost'):
        path = path[len('http://localhost'):]
    request_string = '%s %s HTTP/1.1\n' % (method, path)
    for key, value in kw.items():
        request_string += '%s: %s\n' % (key, value)
    if data is not None:
        request_string += '\r\n'
        request_string += data
    return http(request_string, handle_errors=False)
def http_call(app, method, path, data=None, handle_errors=False, **kw):
    """Function to help make RESTful calls.

    method - HTTP method to use
    path - testbrowser style path
    data - (body) data to submit
    kw - any request parameters
    """
    if path.startswith('http://localhost'):
        path = path[len('http://localhost'):]
    request_string = '{} {} HTTP/1.1\n'.format(method, path)
    for key, value in kw.items():
        request_string += '{}: {}\n'.format(key, value)
    if data is not None:
        request_string += 'Content-Length:{}\n'.format(len(data))
        request_string += '\r\n'
        request_string += data

    if six.PY3:
        request_string = request_string.encode()

    result = http(app, request_string, handle_errors=handle_errors)
    return result
Exemplo n.º 7
0
def http_call(app, method, path, data=None, handle_errors=False, **kw):
    """Function to help make RESTful calls.

    method - HTTP method to use
    path - testbrowser style path
    data - (body) data to submit
    kw - any request parameters
    """
    if path.startswith('http://localhost'):
        path = path[len('http://localhost'):]
    request_string = '{} {} HTTP/1.1\n'.format(method, path)
    for key, value in kw.items():
        request_string += '{}: {}\n'.format(key, value)
    if data is not None:
        request_string += 'Content-Length:{}\n'.format(len(data))
        request_string += '\r\n'
        request_string += data

    if six.PY3:
        request_string = request_string.encode()

    result = http(app, request_string, handle_errors=handle_errors)
    return result
 def _http(query_str, *args, **kwargs):
     wsgi_app = AppContainerLayer.make_wsgi_app()
     # Strip leading \n
     query_str = query_str.lstrip()
     return http(wsgi_app, query_str, *args, **kwargs)