def test_uploader_bad_dirname(self): self.client.connection.put_container = Mock() self.client.connection.head_container = Mock() fake_upload_key = "abcd" uploader = FakeFolderUploader("root", "cont", "*.bad", fake_upload_key, self.client) ret = uploader.upload_files_in_folder(None, "folder.bad", ["a", "b"]) self.assertFalse(ret)
def test_upload_folder_with_files(self): client = self.client up = client.upload_file client.upload_file = Mock() client.connection.head_container = Mock() client.connection.put_container = Mock() cont_name = utils.random_name() cont = client.create_container(cont_name) gobj = client.get_object client.get_object = Mock(return_value=self.fake_object) safu = client._should_abort_folder_upload client._should_abort_folder_upload = Mock(return_value=False) upprog = client._update_progress client._update_progress = Mock() num_files = 10 fake_upload_key = "abcd" with utils.SelfDeletingTempDirectory() as tmpdir: for idx in xrange(num_files): nm = "file%s" % idx pth = os.path.join(tmpdir, nm) open(pth, "w").write("test") uploader = FakeFolderUploader(tmpdir, cont, "", fake_upload_key, client) # Note that the fake moved the actual run() code to a # different method uploader.actual_run() self.assertEqual(client.upload_file.call_count, num_files) client.get_object = gobj client.upload_file = up client._should_abort_folder_upload = safu client._update_progress = upprog
def test_uploader_consider(self): self.client.connection.put_container = Mock() self.client.connection.head_container = Mock() fake_upload_key = "abcd" uploader = FakeFolderUploader("root", "cont", "*.bad", fake_upload_key, self.client) self.assertFalse(uploader.consider("some.bad")) self.assertTrue(uploader.consider("some.good"))
def test_upload_folder_with_files(self): client = self.client up = client.upload_file client.upload_file = Mock() client.connection.head_container = Mock() client.connection.put_container = Mock() cont_name = utils.random_name() cont = client.create_container(cont_name) gobj = client.get_object client.get_object = Mock(return_value=self.fake_object) safu = client._should_abort_folder_upload client._should_abort_folder_upload = Mock(return_value=False) upprog = client._update_progress client._update_progress = Mock() num_files = 10 fake_upload_key = "abcd" with utils.SelfDeletingTempDirectory() as tmpdir: for idx in xrange(num_files): nm = "file%s" % idx pth = os.path.join(tmpdir, nm) open(pth, "w").write("test") uploader = FakeFolderUploader(tmpdir, cont, "", fake_upload_key, client) # Note that the fake moved the actual run() code to a # different method uploader.actual_run() self.assertEqual(client.upload_file.call_count, num_files) client.get_object = gobj client.upload_file = up client._should_abort_folder_upload = safu client._update_progress = upprog
def test_uploader_bad_dirname(self): self.client.connection.put_container = Mock() self.client.connection.head_container = Mock() fake_upload_key = "abcd" uploader = FakeFolderUploader("root", "cont", "*.bad", fake_upload_key, self.client) ret = uploader.upload_files_in_folder(None, "folder.bad", ["a", "b"]) self.assertFalse(ret)
def test_folder_name_from_path(self): self.client.connection.put_container = Mock() self.client.connection.head_container = Mock() fake_upload_key = "abcd" uploader = FakeFolderUploader("root", "cont", None, fake_upload_key, self.client) path1 = "/foo/bar/baz" path2 = "/foo/bar/baz" nm1 = uploader.folder_name_from_path(path1) nm2 = uploader.folder_name_from_path(path2) self.assertEqual(nm1, "baz") self.assertEqual(nm2, "baz")
def test_folder_name_from_path(self): self.client.connection.put_container = Mock() self.client.connection.head_container = Mock() fake_upload_key = "abcd" uploader = FakeFolderUploader("root", "cont", None, fake_upload_key, self.client) path1 = "/foo/bar/baz" path2 = "/foo/bar/baz" nm1 = uploader.folder_name_from_path(path1) nm2 = uploader.folder_name_from_path(path2) self.assertEqual(nm1, "baz") self.assertEqual(nm2, "baz")