Skip to content

Commit c573eab

Browse files
peter-zheng-gbusunkim96
authored andcommitted
[Asset] Add requirements.txt [(#1834)](#1834)
Adds asset quickstart
1 parent 3b41bf1 commit c573eab

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

asset/snippets/snippets/quickstart_exportassets.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ def export_assets(project_id, dump_file_path):
2323
from google.cloud import asset_v1beta1
2424
from google.cloud.asset_v1beta1.proto import asset_service_pb2
2525

26-
# TODO project_id = "Your Google Cloud Project ID"
27-
# TODO dump_file_path = "Your asset dump file path"
26+
# TODO project_id = 'Your Google Cloud Project ID'
27+
# TODO dump_file_path = 'Your asset dump file path'
2828

2929
client = asset_v1beta1.AssetServiceClient()
3030
parent = client.project_path(project_id)
3131
output_config = asset_service_pb2.OutputConfig()
3232
output_config.gcs_destination.uri = dump_file_path
3333
response = client.export_assets(parent, output_config)
34-
print(response.result)
34+
print(response.result())
3535
# [END asset_quickstart_exportassets]
3636

3737

@@ -42,9 +42,10 @@ def export_assets(project_id, dump_file_path):
4242
formatter_class=argparse.RawDescriptionHelpFormatter
4343
)
4444
parser.add_argument('project_id', help='Your Google Cloud project ID')
45-
parser.add_argument('dump_file_path',
46-
help='The file ExportAssets API will dump assets to, '
47-
'e.g.: gs://<bucket-name>/asset_dump_file')
45+
parser.add_argument(
46+
'dump_file_path',
47+
help='The file ExportAssets API will dump assets to, '
48+
'e.g.: gs://<bucket-name>/asset_dump_file')
4849

4950
args = parser.parse_args()
5051

asset/snippets/snippets/quickstart_exportassets_test.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
# limitations under the License.
1616

1717
import os
18+
import time
1819

1920
from google.cloud import storage
2021
import pytest
2122

2223
import quickstart_exportassets
2324

2425
PROJECT = os.environ['GCLOUD_PROJECT']
25-
BUCKET = 'bucket-for-assets'
26+
BUCKET = 'assets-{}'.format(int(time.time()))
2627

2728

2829
@pytest.fixture(scope='module')
@@ -36,15 +37,16 @@ def asset_bucket(storage_client):
3637

3738
try:
3839
storage_client.delete_bucket(BUCKET)
39-
except Exception:
40-
pass
40+
except Exception as e:
41+
print('Failed to delete bucket{}'.format(BUCKET))
42+
raise e
4143

4244
yield BUCKET
4345

4446

4547
def test_export_assets(asset_bucket, capsys):
46-
dump_file_path = "gs://", asset_bucket, "/assets-dump.txt"
48+
dump_file_path = 'gs://{}/assets-dump.txt'.format(asset_bucket)
4749
quickstart_exportassets.export_assets(PROJECT, dump_file_path)
4850
out, _ = capsys.readouterr()
4951

50-
assert "uri: \"gs://cai-prober-prod-for-assets/phython-test.txt\"" in out
52+
assert dump_file_path in out
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
google-cloud-storage==1.13.0
2+
google-cloud-asset==0.1.1

0 commit comments

Comments
 (0)