Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def main(l):
async with aiohttp.ClientSession(loop=l) as session:
with async_timeout.timeout(3):
async with session.get(url) as get_response:
assert get_response.status == 404
assert await get_response.text() == body
with async_timeout.timeout(3):
async with session.post(url, data=body * 6) as post_response:
assert post_response.status == 201
assert await post_response.text() == body * 2
assert Mocket.last_request().method == 'POST'
assert Mocket.last_request().body == body * 6
def test_get_unicode(self):
Entry.register_response('GET snowman', '\u2603')
self.assertEqual(self.rclient.get('snowman'), b'\xe2\x98\x83')
self.assertEqual(len(Mocket._requests), 1)
self.assertEqual(Mocket.last_request().data, b'*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n')
async def main(l):
async with aiohttp.ClientSession(loop=l) as session:
with async_timeout.timeout(3):
async with session.get(url) as get_response:
assert get_response.status == 404
assert await get_response.text() == body
with async_timeout.timeout(3):
async with session.post(url, data=body * 6) as post_response:
assert post_response.status == 201
assert await post_response.text() == body * 2
assert Mocket.last_request().method == 'POST'
assert Mocket.last_request().body == body * 6
def test_set(self):
Entry.register_response('SET mocket "is awesome!"', OK)
self.assertTrue(self.rclient.set('mocket', 'is awesome!'))
self.assertEqual(len(Mocket._requests), 1)
self.assertEqual(Mocket.last_request().data, b'*3\r\n$3\r\nSET\r\n$6\r\nmocket\r\n$11\r\nis awesome!\r\n')
def test_lrange(self):
l = [b'one', b'two', b'three']
Entry.register_response('LRANGE list 0 -1', l)
self.assertEqual(self.rclient.lrange('list', 0, -1), l)
self.assertEqual(len(Mocket._requests), 1)
self.assertEqual(Mocket.last_request().data, b'*4\r\n$6\r\nLRANGE\r\n$4\r\nlist\r\n$1\r\n0\r\n$2\r\n-1\r\n')
def test_lastrequest(self):
self.assertEqual(Mocket.last_request(), None)
Mocket._requests.extend([1, 2, 3])
self.assertEqual(Mocket.last_request(), 3)
def send(self, data, *args, **kwargs): # pragma: no cover
entry = self.get_entry(data)
if entry and self._entry != entry:
self.sendall(data, entry=entry, *args, **kwargs)
else:
req = Mocket.last_request()
if hasattr(req, "add_data"):
req.add_data(decode_from_bytes(data))
self._entry = entry
return len(data)