|
| 1 | +# Copyright 2020 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import datetime |
| 16 | +import os |
| 17 | + |
| 18 | +from google.cloud import automl_v1beta1 as automl |
| 19 | +import pytest |
| 20 | + |
| 21 | +import delete_dataset |
| 22 | + |
| 23 | +PROJECT_ID = os.environ["AUTOML_PROJECT_ID"] |
| 24 | +BUCKET_ID = "{}-lcm".format(PROJECT_ID) |
| 25 | + |
| 26 | + |
| 27 | +@pytest.fixture(scope="function") |
| 28 | +def dataset_id(): |
| 29 | + client = automl.AutoMlClient() |
| 30 | + project_location = client.location_path(PROJECT_ID, "us-central1") |
| 31 | + display_name = "test_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S") |
| 32 | + metadata = automl.types.TextExtractionDatasetMetadata() |
| 33 | + dataset = automl.types.Dataset( |
| 34 | + display_name=display_name, text_extraction_dataset_metadata=metadata |
| 35 | + ) |
| 36 | + dataset = client.create_dataset(project_location, dataset) |
| 37 | + dataset_id = dataset.name.split("/")[-1] |
| 38 | + |
| 39 | + yield dataset_id |
| 40 | + |
| 41 | + |
| 42 | +def test_delete_dataset(capsys, dataset_id): |
| 43 | + # delete dataset |
| 44 | + delete_dataset.delete_dataset(PROJECT_ID, dataset_id) |
| 45 | + out, _ = capsys.readouterr() |
| 46 | + assert "Dataset deleted." in out |
0 commit comments