def setUp(self): self.request = AWSRequest(url='http://example.com') self.prepared_request = AWSPreparedRequest(self.request) self.har_request = HarRequest({ 'url': 'http://example.com', 'method': 'GET', 'cookies': {}, 'headers': {}, 'queryString': [], 'postData': {'mimeType': ''}, })
class TestAWSPreparedRequest(unittest.TestCase): def setUp(self): self.tempdir = tempfile.mkdtemp() self.filename = os.path.join(self.tempdir, 'foo') self.request = AWSRequest(url='http://example.com') self.prepared_request = AWSPreparedRequest(self.request) self.prepared_request.prepare_headers(self.request.headers) def tearDown(self): shutil.rmtree(self.tempdir) def test_prepare_body_content_adds_content_length(self): content = b'foobarbaz' with open(self.filename, 'wb') as f: f.write(content) with open(self.filename, 'rb') as f: data = Seekable(f) self.prepared_request.prepare_body(data=data, files=None) self.assertEqual( self.prepared_request.headers['Content-Length'], str(len(content))) def test_prepare_body_removes_transfer_encoding(self): self.prepared_request.headers['Transfer-Encoding'] = 'chunked' content = b'foobarbaz' with open(self.filename, 'wb') as f: f.write(content) with open(self.filename, 'rb') as f: data = Seekable(f) self.prepared_request.prepare_body(data=data, files=None) self.assertEqual( self.prepared_request.headers['Content-Length'], str(len(content))) self.assertNotIn('Transfer-Encoding', self.prepared_request.headers) def test_prepare_body_ignores_existing_transfer_encoding(self): content = b'foobarbaz' self.prepared_request.headers['Transfer-Encoding'] = 'chunked' with open(self.filename, 'wb') as f: f.write(content) with open(self.filename, 'rb') as f: self.prepared_request.prepare_body(data=f, files=None) # The Transfer-Encoding should not be removed if Content-Length # is not added via the custom logic in the ``prepare_body`` method. # Note requests' ``prepare_body`` is the method that adds the # Content-Length header for this case as the ``data`` is a # regular file handle. self.assertEqual( self.prepared_request.headers['Transfer-Encoding'], 'chunked')
class TestAWSPreparedRequest(unittest.TestCase): def setUp(self): self.tempdir = tempfile.mkdtemp() self.filename = os.path.join(self.tempdir, 'foo') self.request = AWSRequest(url='http://example.com') self.prepared_request = AWSPreparedRequest(self.request) self.prepared_request.prepare_headers(self.request.headers) def tearDown(self): shutil.rmtree(self.tempdir) def test_prepare_body_content_adds_content_length(self): content = b'foobarbaz' with open(self.filename, 'wb') as f: f.write(content) with open(self.filename, 'rb') as f: data = Seekable(f) self.prepared_request.prepare_body(data=data, files=None) self.assertEqual(self.prepared_request.headers['Content-Length'], str(len(content))) def test_prepare_body_removes_transfer_encoding(self): self.prepared_request.headers['Transfer-Encoding'] = 'chunked' content = b'foobarbaz' with open(self.filename, 'wb') as f: f.write(content) with open(self.filename, 'rb') as f: data = Seekable(f) self.prepared_request.prepare_body(data=data, files=None) self.assertEqual(self.prepared_request.headers['Content-Length'], str(len(content))) self.assertNotIn('Transfer-Encoding', self.prepared_request.headers) def test_prepare_body_ignores_existing_transfer_encoding(self): content = b'foobarbaz' self.prepared_request.headers['Transfer-Encoding'] = 'chunked' with open(self.filename, 'wb') as f: f.write(content) with open(self.filename, 'rb') as f: self.prepared_request.prepare_body(data=f, files=None) # The Transfer-Encoding should not be removed if Content-Length # is not added via the custom logic in the ``prepare_body`` method. # Note requests' ``prepare_body`` is the method that adds the # Content-Length header for this case as the ``data`` is a # regular file handle. self.assertEqual(self.prepared_request.headers['Transfer-Encoding'], 'chunked')
def setUp(self): self.tempdir = tempfile.mkdtemp() self.filename = os.path.join(self.tempdir, 'foo') self.request = AWSRequest(url='http://example.com') self.prepared_request = AWSPreparedRequest(self.request) self.prepared_request.prepare_headers(self.request.headers)
def test_parse_qs_unicode_decode_error(): body = b'{"key": "%D0"}, "C": "#0 = :0"}' request = AWSPreparedRequest("GET", "http://request", {"foo": "bar"}, body, False) BaseResponse().setup_class(request, request.url, request.headers)
def encode_HarRequest_to_AWSPreparedRequest(self, har): from botocore.awsrequest import AWSPreparedRequest req = self.encode_HarRequest_to_AWSRequest(har) preq = AWSPreparedRequest(req) return preq
def test_parse_qs_unicode_decode_error(): body = b'{"key": "%D0"}, "C": "#0 = :0"}' request = AWSPreparedRequest('GET', 'http://request', {'foo': 'bar'}, body, False) BaseResponse().setup_class(request, request.url, request.headers)