예제 #1
0
def tester(request):
    """Tester fixture."""
    class Handler(RequestHandler):
        def get(self):
            self.write('Hello')

    app = Application([url('/hello', Handler)])

    tester = Tester(app)
    tester.setup()
    request.addfinalizer(tester.teardown)
    return tester
예제 #2
0
def test_reuse():
    """Tester is not reusable."""
    class Handler(RequestHandler):
        def get(self):
            self.write('Hello')

    app = Application([url('/hello', Handler)])

    tester = Tester(app)
    with tester:
        response = yield tester.http_client.fetch(tester.url_for('/hello'))
        assert 'Hello' == text_body(response)

    with pytest.raises(RuntimeError):
        tester.setup()
예제 #3
0
def test_another_loop():
    """We can handle only one I/O loop per test."""
    class Handler(RequestHandler):
        def get(self):
            self.write('Hello')

    app = Application([url('/hello', Handler)])

    tester1 = Tester(app)
    with tester1:
        response = yield tester1.http_client.fetch(
            tester1.url_for('/hello'))
        assert 'Hello' == text_body(response)

    tester2 = Tester(app)
    with tester2:
        with pytest.raises(RuntimeError):
            yield tester2.http_client.fetch(
                tester2.url_for('/hello'))
예제 #4
0
def test_shared_loop():
    """But, we can use same I/O loop in multiple testers."""
    class Handler(RequestHandler):
        def get(self):
            self.write('Hello')

    app = Application([url('/hello', Handler)])

    io_loop = tornado.ioloop.IOLoop()

    tester1 = Tester(app, io_loop=io_loop)
    with tester1:
        response = yield tester1.http_client.fetch(
            tester1.url_for('/hello'))
        assert 'Hello' == text_body(response)

    tester2 = Tester(app, io_loop=io_loop)
    with tester2:
        response = yield tester2.http_client.fetch(
            tester2.url_for('/hello'))
        assert 'Hello' == text_body(response)
예제 #5
0
def test_fixture(tester: Tester):
    """Test tester fixture."""
    response = yield tester.http_client.fetch(tester.url_for('/hello'))
    assert 'Hello' == text_body(response)