Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(self):
x = http.Request('http://foo', method='POST')
assert x.url == 'http://foo'
assert x.method == 'POST'
x = http.Request('x', max_redirects=100)
assert x.max_redirects == 100
assert isinstance(x.headers, http.Headers)
h = http.Headers()
x = http.Request('x', headers=h)
assert x.headers is h
assert isinstance(x.on_ready, promise)
def test_call_soon__promise_argument(self):
callback = promise(Mock(name='callback'), (1, 2, 3))
ret = self.hub.call_soon(callback)
assert ret is callback
assert ret in self.hub._ready
x = AsyncAWSAuthConnection('aws.vandelay.com',
http_client=Mock(name='client'))
Conn = x.get_http_connection = Mock(name='get_http_connection')
request = x.build_base_http_request('GET', 'foo', '/auth')
callback = PromiseMock(name='callback')
x._mexe(request, callback=callback)
Conn.return_value.request.assert_called_with(
request.method, request.path, request.body, request.headers,
)
Conn.return_value.getresponse.assert_called_with(
callback=callback,
)
no_callback_ret = x._mexe(request)
# _mexe always returns promise
assert isinstance(no_callback_ret, Thenable)
def test_getresponse(self):
client = Mock(name='client')
client.add_request = passthrough(name='client.add_request')
x = AsyncHTTPConnection('aws.vandelay.com', http_client=client)
x.Response = Mock(name='x.Response')
request = x.getresponse()
x.http_client.add_request.assert_called_with(request)
assert isinstance(request, Thenable)
assert isinstance(request.on_ready, Thenable)
response = Mock(name='Response')
request.on_ready(response)
x.Response.assert_called_with(response)
def test_getresponse(self):
client = Mock(name='client')
client.add_request = passthrough(name='client.add_request')
x = AsyncHTTPSConnection(http_client=client)
x.Response = Mock(name='x.Response')
request = x.getresponse()
x.http_client.add_request.assert_called_with(request)
assert isinstance(request, Thenable)
assert isinstance(request.on_ready, Thenable)
response = Mock(name='Response')
request.on_ready(response)
x.Response.assert_called_with(response)
def test_getresponse(self):
client = Mock(name='client')
client.add_request = passthrough(name='client.add_request')
x = AsyncHTTPSConnection(http_client=client)
x.Response = Mock(name='x.Response')
request = x.getresponse()
x.http_client.add_request.assert_called_with(request)
assert isinstance(request, Thenable)
assert isinstance(request.on_ready, Thenable)
response = Mock(name='Response')
request.on_ready(response)
x.Response.assert_called_with(response)
@wraps(fun)
def _commit(*args, **kwargs):
with transaction.atomic():
return fun(*args, **kwargs)
return _commit
def send_ack(response, pid, job, fd):
# Only used when synack is enabled.
# Schedule writing ack response for when the fd is writable.
msg = Ack(job, fd, precalc[response])
callback = promise(write_generator_done)
cor = _write_ack(fd, msg, callback=callback)
mark_write_gen_as_active(cor)
mark_write_fd_as_active(fd)
callback.args = (cor,)
add_writer(fd, cor)
self.send_ack = send_ack
def call_soon(self, callback, *args):
if not isinstance(callback, Thenable):
callback = promise(callback, args)
self._ready.add(callback)
return callback
def _schedule_queue(self, queue):
if queue in self._active_queues:
if self.qos.can_consume():
self._get_bulk_async(
queue, callback=promise(self._loop1, (queue,)),
)
else:
self._loop1(queue)