def test_download_interrupted(self, http_server): binary_file = bytearray(random.getrandbits(8) for _ in range(4096)) def handler(self): self.send_response(200) self.send_header('Content-Length', len(binary_file) * 2) self.end_headers() self.wfile.write(binary_file) http_server.handler.do_GET = handler req = Request(Request.DOWNLOAD, 'GET', http_server.base_uri, {}) with pytest.raises(InterruptedDownloadError): with http_server: send_request.download(req, self.session)
def test_download(self, http_server): binary_file = bytearray(random.getrandbits(8) for _ in range(4096)) def handler(self): self.send_response(200) self.end_headers() self.wfile.write(binary_file) http_server.handler.do_GET = handler req = Request(Request.DOWNLOAD, 'GET', http_server.base_uri, {}) with http_server: result = send_request.download(req, self.session) assert result.get('code') is 200 buffer = b'' with result.get('content') as dl_file: buffer += dl_file.read() assert buffer == binary_file