How to use the cheroot.test.webtest function in cheroot

To help you get started, we’ve selected a few cheroot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmwm / WMCore / test / python / WMCore_t / REST_t / Daemon_t.py View on Github external
"""Get the status of all our registered tasks."""
        print("AMR status get request received")
        return self.gather(self._tasks)

class TaskAPI(RESTApi):
    """REST API which runs a bunch of pseudo tasks, and provides a REST
    entity to report their status via HTTP GET."""
    def __init__(self, app, config, mount):
        RESTApi.__init__(self, app, config, mount)
        print("AMR mounting RESTApi app: %s, config: %s, mount: %s" % (app, config, mount))
        tasks = [Task() for _ in xrange(0, 10)]
        self._add({ "status": Status(app, self, config, mount, tasks) })
        print("AMR done mounting the 'status' API")


class TaskTest(webtest.WebCase):
    """Client to verify :class:`TaskAPI` works."""
    def setUp(self):
        self.h = fake_authz_headers(FAKE_FILE.data)
        webtest.WebCase.PORT = PORT
        self.engine = cherrypy.engine
        self.proc = load_server(self.engine)
        print("AMR server loaded")

    def tearDown(self):
        stop_server(self.proc, self.engine)

    def test(self):
        h = self.h
        h.append(("Accept", "application/json"))
        print("AMR headers: %s" % h)
        print(self.getPage("/test", headers=h))
github dmwm / WMCore / test / python / WMCore_t / REST_t / Api_t.py View on Github external
proc.join(timeout=1)
    return proc

def start_server(engine):
    webtest.WebCase.PORT = PORT
    cherrypy.log.screen = True
    engine.start()
    engine.block()

def stop_server(proc, engine):
    cherrypy.log.screen = True
    engine.stop()
    proc.terminate()

if __name__ == '__main__':
    webtest.main()
github cherrypy / cheroot / cheroot / testing.py View on Github external
def request(
        self, uri, method='GET', headers=None, http_conn=None,
        protocol='HTTP/1.1',
    ):
        return webtest.openURL(
            uri, method=method,
            headers=headers,
            host=self._host, port=self._port,
            http_conn=http_conn or self._http_connection,
            protocol=protocol,
        )
github h3llrais3r / Auto-Subliminal / lib / cheroot / testing.py View on Github external
def _get_conn_data(bind_addr):
    if isinstance(bind_addr, tuple):
        host, port = bind_addr
    else:
        host, port = bind_addr, 0

    interface = webtest.interface(host)

    if ':' in interface and not _probe_ipv6_sock(interface):
        interface = '127.0.0.1'
        if ':' in host:
            host = interface

    return interface, host, port
github dmwm / WMCore / test / python / WMCore_t / REST_t / Api_t.py View on Github external
class Image(RESTEntity):
    def validate(self, *args): pass

    @restcall(formats=[("image/gif", RawFormat())])
    @tools.expires(secs=300)
    def get(self):
        return gif_bytes

class Root(RESTApi):
    def __init__(self, app, config, mount):
        RESTApi.__init__(self, app, config, mount)
        self._add({ "simple": Simple(app, self, config, mount),
                    "image":  Image(app, self, config, mount),
                    "multi":  Multi(app, self, config, mount) })

class Tester(webtest.WebCase):

    def setUp(self):
        self.h = fake_authz_headers(FAKE_FILE.data)
        webtest.WebCase.PORT = PORT
        self.engine = cherrypy.engine
        self.proc = load_server(self.engine)

    def tearDown(self):
        stop_server(self.proc, self.engine)

    def _test_accept_ok(self, fmt, page = "/test/simple", inbody = None):
        h = self.h + [("Accept", fmt)]
        self.getPage(page, headers = h)
        self.assertStatus("200 OK")
        if fmt.find("*") >= 0:
            self.assertHeader("Content-Type")
github dmwm / WMCore / test / python / WMCore_t / REST_t / Daemon_t.py View on Github external
proc.join(timeout=1)
    return proc

def start_server(engine):
    webtest.WebCase.PORT = PORT
    cherrypy.log.screen = True
    engine.start()
    engine.block()

def stop_server(proc, engine):
    cherrypy.log.screen = True
    engine.stop()
    proc.terminate()

if __name__ == '__main__':
    webtest.main()
github cherrypy / cheroot / cheroot / testing.py View on Github external
def _get_conn_data(bind_addr):
    if isinstance(bind_addr, tuple):
        host, port = bind_addr
    else:
        host, port = bind_addr, 0

    interface = webtest.interface(host)

    if ':' in interface and not _probe_ipv6_sock(interface):
        interface = '127.0.0.1'
        if ':' in host:
            host = interface

    return interface, host, port
github dmwm / WMCore / test / python / WMCore_t / REST_t / Simple_t.py View on Github external
proc.join(timeout=1)
    return proc

def start_server(engine):
    webtest.WebCase.PORT = PORT
    cherrypy.log.screen = True
    engine.start()
    engine.block()

def stop_server(proc, engine):
    cherrypy.log.screen = True
    engine.stop()
    proc.terminate()

if __name__ == '__main__':
    webtest.main()