Esempio n. 1
0
 def test_add_md5_with_file_like_body(self):
     request_dict = {
         'body': six.BytesIO(b'foobar'),
         'headers': {}
     }
     self.md5_digest.return_value = b'8X\xf6"0\xac<\x91_0\x0cfC\x12\xc6?'
     handlers.calculate_md5(request_dict)
     self.assertEqual(request_dict['headers']['Content-MD5'],
                      'OFj2IjCsPJFfMAxmQxLGPw==')
Esempio n. 2
0
    def test_add_md5_raises_error_when_md5_unavailable(self):
        credentials = Credentials('key', 'secret')
        request_signer = RequestSigner(
            's3', 'us-east-1', 's3', 's3', credentials, mock.Mock())
        request_dict = {'body': b'bar',
                        'url': 'https://s3.us-east-1.amazonaws.com',
                        'method': 'PUT',
                        'headers': {}}

        self.set_md5_available(False)
        with self.assertRaises(MD5UnavailableError):
            handlers.calculate_md5(
                request_dict, request_signer=request_signer)