Exemplo n.º 1
0
    def test_binds_to_the_specified_port(self, app):
        capybara.server_host = "127.0.0.1"
        server = Server(app).boot()
        with closing(urlopen("http://127.0.0.1:{}".format(
                server.port))) as response:
            assert "Hello Server" in decode_bytes(response.read())

        capybara.server_host = "0.0.0.0"
        server = Server(app).boot()
        with closing(urlopen("http://127.0.0.1:{}".format(
                server.port))) as response:
            assert "Hello Server" in decode_bytes(response.read())
Exemplo n.º 2
0
    def test_uses_the_existing_server_if_it_is_already_running(self, app):
        server1 = Server(app).boot()
        server2 = Server(app).boot()

        with closing(urlopen("http://{}:{}".format(
                server1.host, server1.port))) as response1:
            assert "Hello Server" in decode_bytes(response1.read())

        with closing(urlopen("http://{}:{}".format(
                server2.host, server2.port))) as response2:
            assert "Hello Server" in decode_bytes(response2.read())

        assert server1.port == server2.port
Exemplo n.º 3
0
    def test_finds_an_available_port(self, app):
        def app2(environ, start_response):
            start_response("200 OK", [])
            return [encode_string("Hello Second Server!")]

        server1 = Server(app).boot()
        server2 = Server(app2).boot()

        with closing(urlopen("http://{}:{}".format(
                server1.host, server1.port))) as response1:
            assert "Hello Server" in decode_bytes(response1.read())

        with closing(urlopen("http://{}:{}".format(
                server2.host, server2.port))) as response2:
            assert "Hello Second Server" in decode_bytes(response2.read())
Exemplo n.º 4
0
    def responsive(self):
        """ bool: Whether the server for this app is up and responsive. """

        if self.server_thread and self.server_thread.join(0):
            return False

        try:
            # Try to fetch the endpoint added by the middleware.
            with closing(urlopen("http://{0}:{1}/__identify__".format(self.host, self.port))) as response:
                body, status_code = response.read(), response.getcode()

                if str(status_code)[0] == "2" or str(status_code)[0] == "3":
                    return wsgi_decode_body(body) == str(id(self.app))
        except URLError:
            pass

        return False
Exemplo n.º 5
0
 def test_uses_given_port(self, app):
     server = Server(app, port=22790).boot()
     with closing(urlopen("http://{}:22790".format(
             server.host))) as response:
         assert "Hello Server" in decode_bytes(response.read())
Exemplo n.º 6
0
 def test_uses_specified_port(self, app):
     capybara.server_port = 22789
     server = Server(app).boot()
     with closing(urlopen("http://{}:22789".format(
             server.host))) as response:
         assert "Hello Server" in decode_bytes(response.read())
Exemplo n.º 7
0
 def test_spools_up_a_wsgi_server(self, app):
     server = Server(app).boot()
     with closing(urlopen("http://{}:{}".format(server.host,
                                                server.port))) as response:
         assert "Hello Server" in decode_bytes(response.read())