コード例 #1
0
 def test_encrypted_upload_wal(self, rfo_mock, boto_mock):
     """
     Test the upload of a WAL
     """
     # Create a simple S3WalUploader obj
     cloud_interface = CloudInterface(
         's3://bucket/path/to/dir', encryption='AES256')
     uploader = S3WalUploader(
         cloud_interface, 'test-server'
     )
     source = '/wal_dir/000000080000ABFF000000C1'
     # Simulate the file object returned by the retrieve_file_obj method
     rfo_mock.return_value.name = source
     uploader.upload_wal(source)
     session_mock = boto_mock.Session.return_value
     s3_client_mock = session_mock.resource.return_value.meta.client
     # Check the call for the creation of the destination key
     s3_client_mock.upload_fileobj.assert_called_once_with(
         Fileobj=rfo_mock.return_value,
         Bucket=cloud_interface.bucket_name,
         Key=os.path.join(
             cloud_interface.path,
             uploader.server_name,
             'wals',
             hash_dir(source),
             os.path.basename(source))[1:],
         ExtraArgs={'ServerSideEncryption': 'AES256'}
     )
コード例 #2
0
 def test_retrieve_normal_file_name(self):
     """
     Test the retrieve_wal_name method with an uncompressed file
     """
     # Create a fake source name
     source = 'wal_dir/000000080000ABFF000000C1'
     uploader = S3WalUploader(mock.MagicMock(), 'test-server')
     wal_final_name = uploader.retrieve_wal_name(source)
     # Check the file name received
     assert wal_final_name
     assert wal_final_name == '000000080000ABFF000000C1'
コード例 #3
0
 def test_retrieve_normal_file_obj(self, boto_mock, tmpdir):
     """
     Test the retrieve_file_obj method with an uncompressed file
     """
     # Setup the WAL file
     source = tmpdir.join('wal_dir/000000080000ABFF000000C1')
     source.write('something'.encode('utf-8'), ensure=True)
     # Create a simple S3WalUploader obj
     uploader = S3WalUploader(mock.MagicMock(), 'test-server')
     open_file = uploader.retrieve_file_obj(source.strpath)
     # Check the file received
     assert open_file
     # Check content
     assert open_file.read() == 'something'.encode('utf-8')
コード例 #4
0
 def test_retrieve_bz2_file_obj(self, boto_mock, tmpdir):
     """
     Test the retrieve_file_obj method with a bz2 file
     """
     # Setup the WAL
     source = tmpdir.join('wal_dir/000000080000ABFF000000C1')
     source.write('something'.encode('utf-8'), ensure=True)
     # Create a simple S3WalUploader obj
     uploader = S3WalUploader(
         mock.MagicMock(), 'test-server', compression='bzip2'
     )
     open_file = uploader.retrieve_file_obj(source.strpath)
     # Check the in memory file received
     assert open_file
     # Decompress on the fly to check content
     assert bz2.decompress(open_file.read()) == 'something'.encode('utf-8')