

def testPorterServiceEcho(self):
    '\n        Test Porter service request response of echo non blocking\n        '
    console.terse('{0}\n'.format(self.testPorterServiceEcho.__doc__))
    store = storing.Store(stamp=0.0)
    console.terse('{0}\n'.format('Building Valet ...\n'))
    wireLogAlpha = wiring.WireLog(buffify=True, same=True)
    result = wireLogAlpha.reopen()
    alpha = serving.Porter(port=6101, bufsize=131072, wlog=wireLogAlpha, store=store)
    self.assertIs(alpha.servant.reopen(), True)
    self.assertEqual(alpha.servant.ha, ('0.0.0.0', 6101))
    self.assertEqual(alpha.servant.eha, ('127.0.0.1', 6101))
    console.terse('{0}\n'.format('Building Patron ...\n'))
    wireLogBeta = wiring.WireLog(buffify=True, same=True)
    result = wireLogBeta.reopen()
    path = 'http://{0}:{1}/'.format('localhost', alpha.servant.eha[1])
    beta = clienting.Patron(bufsize=131072, wlog=wireLogBeta, store=store, path=path, reconnectable=True)
    self.assertIs(beta.connector.reopen(), True)
    self.assertIs(beta.connector.accepted, False)
    self.assertIs(beta.connector.connected, False)
    self.assertIs(beta.connector.cutoff, False)
    request = odict([('method', 'GET'), ('path', '/echo?name=fame'), ('qargs', odict()), ('fragment', ''), ('headers', odict([('Accept', 'application/json'), ('Content-Length', 0)]))])
    beta.requests.append(request)
    while (beta.requests or beta.connector.txes or (not beta.responses) or (not alpha.servant.ixes) or (not alpha.idle())):
        alpha.serviceAll()
        time.sleep(0.05)
        beta.serviceAll()
        time.sleep(0.05)
    self.assertIs(beta.connector.accepted, True)
    self.assertIs(beta.connector.connected, True)
    self.assertIs(beta.connector.cutoff, False)
    self.assertEqual(len(alpha.servant.ixes), 1)
    self.assertEqual(len(alpha.stewards), 1)
    requestant = alpha.stewards.values()[0].requestant
    self.assertEqual(requestant.method, request['method'])
    self.assertEqual(requestant.url, request['path'])
    self.assertEqual(requestant.headers, {
        'accept': 'application/json',
        'accept-encoding': 'identity',
        'content-length': '0',
        'host': 'localhost:6101',
    })
    self.assertEqual(len(beta.responses), 1)
    response = beta.responses.popleft()
    self.assertEqual(response['data'], {
        'body': '',
        'data': None,
        'fragment': '',
        'headers': {
            'accept': 'application/json',
            'accept-encoding': 'identity',
            'content-length': '0',
            'host': 'localhost:6101',
        },
        'method': 'GET',
        'path': '/echo',
        'qargs': {
            'name': 'fame',
        },
        'version': 'HTTP/1.1',
    })
    responder = alpha.stewards.values()[0].responder
    self.assertEqual(responder.status, response['status'])
    self.assertEqual(responder.headers, response['headers'])
    alpha.servant.closeAll()
    beta.connector.close()
    wireLogAlpha.close()
    wireLogBeta.close()

dataset/ETHPy150Open ioflo/ioflo/ioflo/aio/http/test/test_serving.py BasicTestCase.testPorterServiceEcho/original