def test_encrypt_in_place(self): s3.cp(self.local_file, self.remote_file("to_encrypt.txt"), encrypt=False) # just make sure there's something to copy self.assertFalse( s3.info(self.remote_file("to_encrypt.txt"))['encrypted']) s3.encrypt_at_rest(self.remote_file("to_encrypt.txt")) self.assertTrue( s3.info(self.remote_file("to_encrypt.txt"))['encrypted'])
def test_s3_cp_content_encoding(self): s3.cp(self.local_file, self.remote_file("encoded.md"), encoding='gzip') self.assertEqual(s3.info(self.remote_file("encoded.md"))['content_encoding'], 'gzip') s3.cp(self.local_file, self.remote_file("notencoded.md")) # just make sure gzip isn't the default ;) self.assertNotEqual(s3.info(self.remote_file("notencoded.md"))['content_encoding'], 'gzip') s3.cp(self.remote_file("encoded.md"), self.remote_file("still_encoded.md")) self.assertEqual(s3.info(self.remote_file("still_encoded.md"))['content_encoding'], 'gzip') s3.cp(self.remote_file("notencoded.md"), self.remote_file("now_encoded.md"), encoding='gzip') self.assertEqual(s3.info(self.remote_file("now_encoded.md"))['content_encoding'], 'gzip')
def test_s3_cp_gzip(self): s3.cp(self.local_file, self.remote_file("big.md")) s3.cp(self.local_file, self.remote_file("small.md"), gzip=True) self.assertNotEqual( s3.info(self.remote_file("big.md"))['content_encoding'], 'gzip') self.assertEqual( s3.info(self.remote_file("small.md"))['content_encoding'], 'gzip') self.assertLess( s3.info(self.remote_file("small.md"))['size'], s3.info(self.remote_file("big.md"))['size'])
def test_upload(self): s3.cp(self.local_file, self.remote_file("unencrypted.txt"), encrypt=False) self.assertFalse( s3.info(self.remote_file("unencrypted.txt"))['encrypted']) s3.cp(self.local_file, self.remote_file("encrypted.txt")) # default now to encrypt self.assertTrue( s3.info(self.remote_file("encrypted.txt"))['encrypted'])
def test_copy(self): s3.cp(self.local_file, self.remote_file("unencrypted.txt"), encrypt=False) # just make sure there's something to copy self.assertFalse( s3.info(self.remote_file("unencrypted.txt"))['encrypted']) s3.cp(self.remote_file("unencrypted.txt"), self.remote_file("encrypted.txt")) self.assertTrue( s3.info(self.remote_file("encrypted.txt"))['encrypted'])
def test_s3_cp_content_type(self): s3.cp(self.local_file, self.remote_file("typed.md"), content_type='text/html') self.assertEqual(s3.info(self.remote_file("typed.md"))['content_type'], 'text/html') s3.cp(self.local_file, self.remote_file("nottyped.md")) # default is self.assertEqual(s3.info(self.remote_file("nottyped.md"))['content_type'], 'application/octet-stream') s3.cp(self.remote_file("typed.md"), self.remote_file("still_typed.md")) self.assertEqual(s3.info(self.remote_file("still_typed.md"))['content_type'], 'text/html') s3.cp(self.remote_file("nottyped.md"), self.remote_file("now_typed.md"), content_type='text/html') self.assertEqual(s3.info(self.remote_file("now_typed.md"))['content_type'], 'text/html')
def test_s3_cp_download_versioned_success_with_valid_version_id(self): version_id = s3.info(self.existing_versioned_remote_file)['version_id'] s3.cp(self.existing_versioned_remote_file, os.path.join(self.tmp_dir, 'DL', 'TEST.foo'), version_id=version_id) self.assertTrue( os.path.exists(os.path.join(self.tmp_dir, 'DL', 'TEST.foo')))
def test_s3_open_read_versioned_remote_file(self): remote_file_name = self.existing_versioned_remote_file version_id = s3.info(remote_file_name)['version_id'] with s3.open(remote_file_name, 'r', version_id=version_id) as f: tempname = f.name self.assertFalse(os.path.exists(tempname))
def test_s3_cp_content_encoding(self): s3.cp(self.local_file, self.remote_file("encoded.md"), encoding='gzip') self.assertEqual( s3.info(self.remote_file("encoded.md"))['content_encoding'], 'gzip') s3.cp(self.local_file, self.remote_file( "notencoded.md")) # just make sure gzip isn't the default ;) self.assertNotEqual( s3.info(self.remote_file("notencoded.md"))['content_encoding'], 'gzip') s3.cp(self.remote_file("encoded.md"), self.remote_file("still_encoded.md")) self.assertEqual( s3.info(self.remote_file("still_encoded.md"))['content_encoding'], 'gzip') s3.cp(self.remote_file("notencoded.md"), self.remote_file("now_encoded.md"), encoding='gzip') self.assertEqual( s3.info(self.remote_file("now_encoded.md"))['content_encoding'], 'gzip')
def test_s3_cp_content_type(self): s3.cp(self.local_file, self.remote_file("typed.md"), content_type='text/html') self.assertEqual( s3.info(self.remote_file("typed.md"))['content_type'], 'text/html') s3.cp(self.local_file, self.remote_file("nottyped.md")) # default is self.assertEqual( s3.info(self.remote_file("nottyped.md"))['content_type'], 'application/octet-stream') s3.cp(self.remote_file("typed.md"), self.remote_file("still_typed.md")) self.assertEqual( s3.info(self.remote_file("still_typed.md"))['content_type'], 'text/html') s3.cp(self.remote_file("nottyped.md"), self.remote_file("now_typed.md"), content_type='text/html') self.assertEqual( s3.info(self.remote_file("now_typed.md"))['content_type'], 'text/html')
def main(self, key): if self.uri: print "-B and --uri are deprecated options" try: keys = s3.ls(key, return_full_urls=True, require_s3_scheme=True, shallow=self.shallow, list_versions=self.list_versions) if self.detail: from baiji.util.console import sizeof_format_human_readable for key in keys: info = s3.info(key) enc = " enc" if info['encrypted'] else " " print "%s\t%s%s\t%s\t%s" % (sizeof_format_human_readable(info['size']), info['last_modified'], enc, key.encode('utf-8'), info['version_id']) else: print u"\n".join(keys).encode('utf-8') except s3.InvalidSchemeException as e: print e return 1
def main(self, key): if self.uri: print "-B and --uri are deprecated options" try: keys = s3.ls(key, return_full_urls=True, require_s3_scheme=True, shallow=self.shallow, list_versions=self.list_versions) if self.detail: from baiji.util.console import sizeof_format_human_readable for key in keys: info = s3.info(key) enc = " enc" if info['encrypted'] else " " print "%s\t%s%s\t%s\t%s" % (sizeof_format_human_readable( info['size']), info['last_modified'], enc, key.encode('utf-8'), info['version_id']) else: print u"\n".join(keys).encode('utf-8') except s3.InvalidSchemeException as e: print e return 1
def test_s3_cp_gzip(self): s3.cp(self.local_file, self.remote_file("big.md")) s3.cp(self.local_file, self.remote_file("small.md"), gzip=True) self.assertNotEqual(s3.info(self.remote_file("big.md"))['content_encoding'], 'gzip') self.assertEqual(s3.info(self.remote_file("small.md"))['content_encoding'], 'gzip') self.assertLess(s3.info(self.remote_file("small.md"))['size'], s3.info(self.remote_file("big.md"))['size'])
def test_s3_cp_download_versioned_success_with_valid_version_id(self): version_id = s3.info(self.existing_versioned_remote_file)['version_id'] s3.cp(self.existing_versioned_remote_file, os.path.join(self.tmp_dir, 'DL', 'TEST.foo'), version_id=version_id) self.assertTrue(os.path.exists(os.path.join(self.tmp_dir, 'DL', 'TEST.foo')))
def test_encrypt_in_place(self): s3.cp(self.local_file, self.remote_file("to_encrypt.txt"), encrypt=False) # just make sure there's something to copy self.assertFalse(s3.info(self.remote_file("to_encrypt.txt"))['encrypted']) s3.encrypt_at_rest(self.remote_file("to_encrypt.txt")) self.assertTrue(s3.info(self.remote_file("to_encrypt.txt"))['encrypted'])
def test_upload(self): s3.cp(self.local_file, self.remote_file("unencrypted.txt"), encrypt=False) self.assertFalse(s3.info(self.remote_file("unencrypted.txt"))['encrypted']) s3.cp(self.local_file, self.remote_file("encrypted.txt")) # default now to encrypt self.assertTrue(s3.info(self.remote_file("encrypted.txt"))['encrypted'])
def test_copy(self): s3.cp(self.local_file, self.remote_file("unencrypted.txt"), encrypt=False) # just make sure there's something to copy self.assertFalse(s3.info(self.remote_file("unencrypted.txt"))['encrypted']) s3.cp(self.remote_file("unencrypted.txt"), self.remote_file("encrypted.txt")) self.assertTrue(s3.info(self.remote_file("encrypted.txt"))['encrypted'])
def main(self, key): for k, v in sorted(s3.info(key).items(), key=lambda x: x[0]): print "%s: %s" % (k, v)