本文整理汇总了Python中treq.testing.StubTreq.flush方法的典型用法代码示例。如果您正苦于以下问题:Python StubTreq.flush方法的具体用法?Python StubTreq.flush怎么用?Python StubTreq.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treq.testing.StubTreq
的用法示例。
在下文中一共展示了StubTreq.flush方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handles_successful_asynchronous_requests
# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import flush [as 别名]
def test_handles_successful_asynchronous_requests(self):
"""
Handle a resource returning NOT_DONE_YET and then later finishing the
response.
"""
rsrc = _EventuallyResponsiveTestResource()
stub = StubTreq(rsrc)
d = stub.request("method", "http://example.com/", data=b"1234")
self.assertNoResult(d)
rsrc.stored_request.finish()
stub.flush()
resp = self.successResultOf(d)
self.assertEqual(resp.code, 200)
示例2: FakeMarathonAPI
# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import flush [as 别名]
class FakeMarathonAPI(object):
app = Klein()
def __init__(self, marathon):
self._marathon = marathon
self.client = StubTreq(self.app.resource())
self.event_requests = []
self._called_get_apps = False
def check_called_get_apps(self):
""" Check and reset the ``_called_get_apps`` flag. """
was_called, self._called_get_apps = self._called_get_apps, False
return was_called
@app.route('/v2/apps', methods=['GET'])
def get_apps(self, request):
self._called_get_apps = True
response = {
'apps': self._marathon.get_apps()
}
request.setResponseCode(200)
write_request_json(request, response)
@app.route('/v2/events', methods=['GET'])
def get_events(self, request):
assert (get_single_header(request.requestHeaders, 'Accept') ==
'text/event-stream')
request.setResponseCode(200)
request.setHeader('Content-Type', 'text/event-stream')
# Push the response headers before any events are written
request.write(b'')
self.client.flush()
def callback(event):
_write_request_event(request, event)
self.client.flush()
self._marathon.attach_event_stream(
callback, _get_event_types(request.args), request.getClientIP())
self.event_requests.append(request)
def finished_errback(failure):
self._marathon.detach_event_stream(callback, request.getClientIP())
self.event_requests.remove(request)
finished = request.notifyFinish()
finished.addErrback(finished_errback)
return finished
示例3: test_handles_successful_asynchronous_requests_with_streaming
# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import flush [as 别名]
def test_handles_successful_asynchronous_requests_with_streaming(self):
"""
Handle a resource returning NOT_DONE_YET and then streaming data back
gradually over time.
"""
rsrc = _EventuallyResponsiveTestResource()
stub = StubTreq(rsrc)
d = stub.request("method", "http://example.com/", data="1234")
self.assertNoResult(d)
chunks = []
rsrc.stored_request.write(b"spam ")
rsrc.stored_request.write(b"eggs")
stub.flush()
resp = self.successResultOf(d)
d = stub.collect(resp, chunks.append)
self.assertNoResult(d)
self.assertEqual(b"".join(chunks), b"spam eggs")
del chunks[:]
rsrc.stored_request.write(b"eggs\r\nspam\r\n")
stub.flush()
self.assertNoResult(d)
self.assertEqual(b"".join(chunks), b"eggs\r\nspam\r\n")
rsrc.stored_request.finish()
stub.flush()
self.successResultOf(d)
示例4: test_handles_successful_asynchronous_requests_with_response_data
# 需要导入模块: from treq.testing import StubTreq [as 别名]
# 或者: from treq.testing.StubTreq import flush [as 别名]
def test_handles_successful_asynchronous_requests_with_response_data(self):
"""
Handle a resource returning NOT_DONE_YET and then sending some data in
the response.
"""
rsrc = _EventuallyResponsiveTestResource()
stub = StubTreq(rsrc)
d = stub.request('method', 'http://example.com/', data="1234")
self.assertNoResult(d)
chunks = []
rsrc.stored_request.write('spam ')
rsrc.stored_request.write('eggs')
stub.flush()
resp = self.successResultOf(d)
d = stub.collect(resp, chunks.append)
self.assertNoResult(d)
self.assertEqual(''.join(chunks), 'spam eggs')
rsrc.stored_request.finish()
stub.flush()
self.successResultOf(d)