def setUp(self): super(TestSync, self).setUp() # Files that are the same on both sides: self.create_random_file_at((self.tmp_dir, self.s3_test_location), 'foo/a.txt') self.create_random_file_at((self.tmp_dir, self.s3_test_location), 'foo/b.txt') self.create_random_file_at((self.tmp_dir, self.s3_test_location), 'foo/bar/c.txt') self.create_random_file_at((self.tmp_dir, self.s3_test_location), 'foo/bar/baz/d.txt') # Files that are different locally and remotely: self.create_random_file_at((self.tmp_dir,), 'foo/x.txt') self.create_random_file_at((self.s3_test_location,), 'foo/x.txt') self.create_random_file_at((self.tmp_dir,), 'foo/bar/x.txt') self.create_random_file_at((self.s3_test_location,), 'foo/bar/x.txt') # Files that are only local: self.create_random_file_at((self.tmp_dir,), 'foo/loc.txt') self.create_random_file_at((self.tmp_dir,), 'foo/bar/loc.txt') # Files that are only remote: self.create_random_file_at((self.s3_test_location,), 'foo/rem.txt') self.create_random_file_at((self.s3_test_location,), 'foo/bar/rem.txt') self.local_dir_to_sync = s3.path.join(self.tmp_dir, 'foo') self.remote_dir_to_sync = s3.path.join(self.s3_test_location, 'foo') self.expected_local_contents = s3.ls(self.local_dir_to_sync) self.expected_remote_contents = [x.replace(self.s3_path+'foo/', '') for x in s3.ls(self.remote_dir_to_sync)] # Annoying directory marker that some clients create; create after making contents lists s3.touch(s3.path.join(self.s3_test_location, 'foo/'))
def test_downloading_a_directory_without_slash_that_is_also_a_file(self): s3.touch(self.remote_file("foo")) s3.touch(self.remote_file("foo/theres_a_file_in_here.txt")) # This should work, so that you have some way to download a legit file that's also a dir s3.cp(self.remote_file("foo"), os.path.join(self.tmp_dir, "foo")) self.assertEqual(len(os.listdir(self.tmp_dir)), 1) # But this will fail, as there's already a file in place so we can't make the dir "foo" with self.assertRaises(s3.S3Exception): s3.cp(self.remote_file("foo/theres_a_file_in_here.txt"), os.path.join(self.tmp_dir, "foo/"))
def setUp(self): super(TestSync, self).setUp() # Files that are the same on both sides: self.create_random_file_at((self.tmp_dir, self.s3_test_location), 'foo/a.txt') self.create_random_file_at((self.tmp_dir, self.s3_test_location), 'foo/b.txt') self.create_random_file_at((self.tmp_dir, self.s3_test_location), 'foo/bar/c.txt') self.create_random_file_at((self.tmp_dir, self.s3_test_location), 'foo/bar/baz/d.txt') # Files that are different locally and remotely: self.create_random_file_at((self.tmp_dir, ), 'foo/x.txt') self.create_random_file_at((self.s3_test_location, ), 'foo/x.txt') self.create_random_file_at((self.tmp_dir, ), 'foo/bar/x.txt') self.create_random_file_at((self.s3_test_location, ), 'foo/bar/x.txt') # Files that are only local: self.create_random_file_at((self.tmp_dir, ), 'foo/loc.txt') self.create_random_file_at((self.tmp_dir, ), 'foo/bar/loc.txt') # Files that are only remote: self.create_random_file_at((self.s3_test_location, ), 'foo/rem.txt') self.create_random_file_at((self.s3_test_location, ), 'foo/bar/rem.txt') self.local_dir_to_sync = s3.path.join(self.tmp_dir, 'foo') self.remote_dir_to_sync = s3.path.join(self.s3_test_location, 'foo') self.expected_local_contents = s3.ls(self.local_dir_to_sync) self.expected_remote_contents = [ x.replace(self.s3_path + 'foo/', '') for x in s3.ls(self.remote_dir_to_sync) ] # Annoying directory marker that some clients create; create after making contents lists s3.touch(s3.path.join(self.s3_test_location, 'foo/'))
def test_downloading_an_implicit_directory_with_slash(self): s3.touch(self.remote_file("foo/theres_a_file_in_here.txt")) with self.assertRaises(ValueError): s3.cp(self.remote_file("foo/"), os.path.join(self.tmp_dir, "foo/")) self.assertEqual(len(os.listdir(self.tmp_dir)), 0)
def main(self, key): s3.touch(key)