def test_list_with_subdir(self, client, _): blob_root_path = "project_path/experiment_id/" gcs_url = "gs://bucket/" + blob_root_path dirname = "model" obj_mock = mock.Mock() file_path = dirname + "/" + "tf.pb" obj_mock.configure_mock(name=blob_root_path + file_path, size=1) subdir_mock = mock.Mock() subdirname = dirname + "/" + "files" subdir_mock.configure_mock(prefixes=(blob_root_path + subdirname + "/", )) mock_results = mock.MagicMock() mock_results.configure_mock(pages=[subdir_mock]) mock_results.__iter__.return_value = [obj_mock] client.return_value.get_bucket.return_value.list_blobs.return_value = ( mock_results) store = GCSService() results = store.list(gcs_url, path=dirname) blobs = results["blobs"] prefixes = results["prefixes"] assert len(blobs) == 1 assert len(prefixes) == 1 assert blobs[0][0] == file_path assert blobs[0][1] == obj_mock.size assert prefixes[0] == subdirname
def test_list_dirs_and_blobs(self, client, _): blob_root_path = "project_path/experiment_id/" gcs_url = "gs://bucket/" + blob_root_path obj1_mock = mock.Mock() file1_path = "fileA" obj1_mock.configure_mock(name=blob_root_path + file1_path, size=1) obj2_mock = mock.Mock() file2_path = "fileB" obj2_mock.configure_mock(name=blob_root_path + file2_path, size=0) dirname = "model1" mock_results = mock.MagicMock() mock_results.configure_mock(prefixes=(blob_root_path + dirname + "/", )) mock_results.__iter__.return_value = [obj1_mock, obj2_mock] client.return_value.list_blobs.return_value = mock_results store = GCSService() results = store.list(gcs_url) blobs = results["blobs"] prefixes = results["prefixes"] assert len(blobs) == 2 assert len(prefixes) == 1 assert blobs[0][0] == file1_path assert blobs[0][1] == obj1_mock.size assert blobs[0][1] == 1 assert blobs[1][0] == file2_path assert blobs[1][1] == obj2_mock.size assert blobs[1][1] == 0 assert prefixes[0] == dirname
def test_list_empty(self, client, _): gcs_url = "gs://bucket/path/to/blob" store = GCSService() client.return_value.get_bucket.return_value.list_blobs.return_value = ( mock.MagicMock()) assert store.list(gcs_url) == {"blobs": [], "prefixes": []}
def test_list_empty(self, client, _): gcs_url = "gs://bucket/path/to/blob" store = GCSService() assert store.list(gcs_url) == {"blobs": [], "prefixes": []}