forked from GoogleCloudPlatform/python-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobs_test.py
77 lines (56 loc) · 2.1 KB
/
jobs_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import pytest
import jobs
GCLOUD_PROJECT = os.getenv("GCLOUD_PROJECT")
TEST_COLUMN_NAME = "zip_code"
TEST_TABLE_PROJECT_ID = "bigquery-public-data"
TEST_DATASET_ID = "san_francisco"
TEST_TABLE_ID = "bikeshare_trips"
@pytest.fixture(scope="session")
def test_job_name():
import google.cloud.dlp
dlp = google.cloud.dlp_v2.DlpServiceClient()
parent = dlp.project_path(GCLOUD_PROJECT)
# Construct job request
risk_job = {
"privacy_metric": {
"categorical_stats_config": {"field": {"name": TEST_COLUMN_NAME}}
},
"source_table": {
"project_id": TEST_TABLE_PROJECT_ID,
"dataset_id": TEST_DATASET_ID,
"table_id": TEST_TABLE_ID,
},
}
response = dlp.create_dlp_job(parent, risk_job=risk_job)
full_path = response.name
# API expects only job name, not full project path
job_name = full_path[full_path.rfind("/") + 1 :]
return job_name
def test_list_dlp_jobs(capsys):
jobs.list_dlp_jobs(GCLOUD_PROJECT)
out, _ = capsys.readouterr()
assert "Job: projects/" in out
def test_list_dlp_jobs_with_filter(capsys):
jobs.list_dlp_jobs(GCLOUD_PROJECT, filter_string="state=DONE")
out, _ = capsys.readouterr()
assert "Job: projects/" in out
def test_list_dlp_jobs_with_job_type(capsys):
jobs.list_dlp_jobs(GCLOUD_PROJECT, job_type="INSPECT_JOB")
out, _ = capsys.readouterr()
assert "Job: projects/" in out
def test_delete_dlp_job(test_job_name, capsys):
jobs.delete_dlp_job(GCLOUD_PROJECT, test_job_name)