示例#1
0
    def _connect():
        conn = client.Connection('localhost:8080')
        conn.maybe_connect()

        connections.append(conn)

        return conn
示例#2
0
def connect(request):
    if request.param == 'example':
        yield partial(client.Connection, 'localhost:8080')
    elif request.param == 'test':
        connection = client.Connection('localhost:8080')
        close = connection.close
        connection.close = lambda: None
        yield lambda: connection
        close()
示例#3
0
def run():
    time.sleep(2)
    for reverse in [True, False]:
        for combination in integration_tests.generators.generate_combinations(
          reverse=reverse):
            conn = client.Connection('localhost:8080')
            time.sleep(2)
            integration_tests.generators.send_requests(
                conn, 200, **combination)
            time.sleep(2)
            conn.close()
    time.sleep(2)
示例#4
0
def test_empty(get_connections_and_wait):
    get_connections, wait = get_connections_and_wait
    conn = client.Connection('localhost:8080')

    assert get_connections() == 1

    conn.maybe_connect()
    time.sleep(.1)

    assert get_connections() == 2

    wait()

    assert get_connections() == 1
示例#5
0
def test_request(get_connections_and_wait):
    get_connections, wait = get_connections_and_wait
    conn = client.Connection('localhost:8080')

    assert get_connections() == 1

    conn.putrequest('GET', '/')
    conn.endheaders()

    assert get_connections() == 2

    wait()
    time.sleep(1)

    assert get_connections() == 1
示例#6
0
def test_pipeline(requests):
    connection = client.Connection('localhost:8080')

    for request in requests:
        connection.putrequest(
            request['method'], request['route_prefix'] +
            ('/not-found' if request['error'] == 'not-found' else '') +
            '{param1}/{param2}'.format_map(request), request['query_string'])
        for name, value in request['headers']:
            connection.putheader(name, value)
        if request['body'] is not None:
            body_len = str(len(request['body']))
            request['headers'].append(('Content-Length', body_len))
            connection.putheader('Content-Length', body_len)
        if request['error'] == 'forced-1':
            request['headers'].append(('Force-Raise', 'forced-1'))
            connection.putheader('Force-Raise', 'forced-1')
        connection.endheaders(request['body'])

    for request in requests:
        response = connection.getresponse()
        assert response.status == 500 if request['error'] else 200
        json_body = response.json
        assert json_body['method'] == request['method']
        if request['error'] != 'not-found':
            assert json_body['route'].startswith(request['route_prefix'])
        else:
            assert json_body['route'] is None
        assert json_body['match_dict'] == \
            {} if request['error'] == 'not-found' else \
            {'p1': request['param1'], 'p2': request['param2']}
        assert json_body['query_string'] == request['query_string']
        assert json_body['headers'] == \
            {k.title(): v for k, v in request['headers']}
        if request['body'] is not None:
            assert base64.b64decode(json_body['body']) == request['body']
        else:
            assert json_body['body'] is None
        if request['error']:
            assert json_body['exception']['type'] == \
                'RouteNotFoundException' if request['error'] == 'not-found' \
                else 'ForcedException'
            assert json_body['exception']['args'] == \
                '' if request['error'] == 'not-found' else request['error']
        else:
            assert 'exception' not in json_body

    connection.close()
示例#7
0
def test_async_pipeline(requests):
    connection = client.Connection('localhost:8080')

    for request in requests:
        connection.putrequest(
            'GET', request['prefix'] +
            ('/not-found' if request['error'] == 'not-found' else '') + '/1/2',
            request['query_string'])
        if request['error'] == 'forced-1':
            connection.putheader('Force-Raise', 'forced-1')

        connection.endheaders()

    for request in requests:
        response = connection.getresponse()
        assert response.status == 500 if request['error'] else 200
        json_body = response.json
        assert json_body['query_string'] == request['query_string']

    connection.close()
示例#8
0
def connection(server):
    conn = client.Connection('localhost:8080')
    yield conn
    conn.close()