Exemplo n.º 1
0
    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 = GCSStore()
        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
Exemplo n.º 2
0
 def test_list_empty(self, client, _):
     gcs_url = 'gs://bucket/path/to/blob'
     store = GCSStore()
     client.return_value.get_bucket.return_value.list_blobs.return_value = mock.MagicMock(
     )
     assert store.list(gcs_url) == {'blobs': [], 'prefixes': []}