8000 dataflow: replace job name underscores with hyphens (#8303) · mhenc/python-docs-samples@8d60ef4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d60ef4

Browse files
authored
dataflow: replace job name underscores with hyphens (GoogleCloudPlatform#8303)
* dataflow: replace job name underscores with hyphens It looks like Dataflow no longer accepts underscores in the job names. Replacing them with hyphens should work. * fix test checks * improve error reporting * fix test name for exception handling
1 parent c5d86e1 commit 8d60ef4

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

dataflow/run_template/main_test.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def dataflow_job_name(request):
6666

6767
# cancel the Dataflow job after running the test
6868
# no need to cancel after the empty_args test - it won't create a job and cancellation will throw an error
69-
if label != "test_run_template_empty":
69+
if label != "test-run-template-empty":
7070
dataflow_jobs_cancel(job_name)
7171
else:
7272
print("No active jobs to cancel, cancelling skipped.")
@@ -86,12 +86,15 @@ def get_job_id_from_name(job_name):
8686
)
8787
response = jobs_request.execute()
8888

89-
# search for the job in the list that has our name (names are unique)
90-
for job in response["jobs"]:
91-
if job["name"] == job_name:
92-
return job["id"]
93-
# if we don't find a job, just return
94-
return
89+
try:
90+
# search for the job in the list that has our name (names are unique)
91+
for job in response["jobs"]:
92+
if job["name"] == job_name:
93+
return job["id"]
94+
# if we don't find a job, just return
95+
return
96+
except Exception as e:
97+
raise ValueError(f"response:\n{response}") from e
9598

9699

97100
# We retry the cancel operation a few times until the job is in a state where it can be cancelled
@@ -115,7 +118,7 @@ def dataflow_jobs_cancel(job_name):
115118

116119

117120
@pytest.mark.parametrize(
118-
"dataflow_job_name", [("test_run_template_empty")], indirect=True
121+
"dataflow_job_name", [("test-run-template-empty")], indirect=True
119122
)
120123
def test_run_template_python_empty_args(app, dataflow_job_name):
121124
project = PROJECT
@@ -125,7 +128,7 @@ def test_run_template_python_empty_args(app, dataflow_job_name):
125128

126129

127130
@pytest.mark.parametrize(
128-
"dataflow_job_name", [("test_run_template_python")], indirect=True
131+
"dataflow_job_name", [("test-run-template-python")], indirect=True
129132
)
130133
def test_run_template_python(app, dataflow_job_name):
131134
project = PROJECT
@@ -135,7 +138,7 @@ def test_run_template_python(app, dataflow_job_name):
135138
"output": "gs://{}/dataflow/wordcount/outputs".format(BUCKET),
136139
}
137140
res = main.run(project, dataflow_job_name, template, parameters)
138-
assert "test_run_template_python" in res["job"]["name"]
141+
assert dataflow_job_name in res["job"]["name"]
139142

140143

141144
def test_run_template_http_empty_args(app):
@@ -145,7 +148,7 @@ def test_run_template_http_empty_args(app):
145148

146149

147150
@pytest.mark.parametrize(
148-
"dataflow_job_name", [("test_run_template_url")], indirect=True
151+
"dataflow_job_name", [("test-run-template-url")], indirect=True
149152
)
150153
def test_run_template_http_url(app, dataflow_job_name):
151154
args = {
@@ -158,11 +161,11 @@ def test_run_template_http_url(app, dataflow_job_name):
158161
with app.test_request_context("/?" + url_encode(args)):
159162
res = main.run_template(flask.request)
160163
data = json.loads(res)
161-
assert "test_run_template_url" in data["job"]["name"]
164+
assert dataflow_job_name in data["job"]["name"]
162165

163166

164167
@pytest.mark.parametrize(
165-
"dataflow_job_name", [("test_run_template_data")], indirect=True
168+
"dataflow_job_name", [("test-run-template-data")], indirect=True
166169
)
167170
def test_run_template_http_data(app, dataflow_job_name):
168171
args = {
@@ -175,11 +178,11 @@ def test_run_template_http_data(app, dataflow_job_name):
175178
with app.test_request_context(data=args):
176179
res = main.run_template(flask.request)
177180
data = json.loads(res)
178-
assert "test_run_template_data" in data["job"]["name"]
181+
assert dataflow_job_name in data["job"]["name"]
179182

180183

181184
@pytest.mark.parametrize(
182-
"dataflow_job_name", [("test_run_template_json")], indirect=True
185+
"dataflow_job_name", [("test-run-template-json")], indirect=True
183186
)
184187
def test_run_template_http_json(app, dataflow_job_name):
185188
args = {
@@ -192,4 +195,4 @@ def test_run_template_http_json(app, dataflow_job_name):
192195
with app.test_request_context(json=args):
193196
res = main.run_template(flask.request)
194197
data = json.loads(res)
195-
assert "test_run_template_json" in data["job"]["name"]
198+
assert dataflow_job_name in data["job"]["name"]

0 commit comments

Comments
 (0)
0