Commit ca3aae00 authored by Xinan Lin's avatar Xinan Lin Committed by LUCI CQ

Add step test data for update_files() in Gerrit module

Thus downstream recipes could run "train" without explicit
mock data everywhere.

BUG=1293270
TEST=train
Recipe-Nontrivial-Roll: build
Recipe-Nontrivial-Roll: chromiumos
Recipe-Nontrivial-Roll: build_limited
Recipe-Nontrivial-Roll: chrome_release
Change-Id: I09f6a27097f400dabd990f6ef61e301a75a39691
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3502768Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Xinan Lin <linxinan@chromium.org>
parent d1d7b0a4
...@@ -349,7 +349,7 @@ Returns: ...@@ -349,7 +349,7 @@ Returns:
&mdash; **def [set\_change\_label](/recipes/recipe_modules/gerrit/api.py#277)(self, host, change, label_name, label_value, name=None, step_test_data=None):** &mdash; **def [set\_change\_label](/recipes/recipe_modules/gerrit/api.py#277)(self, host, change, label_name, label_value, name=None, step_test_data=None):**
&mdash; **def [update\_files](/recipes/recipe_modules/gerrit/api.py#319)(self, host, project, branch, new_contents_by_file_path, commit_msg, params=frozenset(['status=NEW']), cc_list=frozenset([]), submit=False, submit_later=False):** &mdash; **def [update\_files](/recipes/recipe_modules/gerrit/api.py#319)(self, host, project, branch, new_contents_by_file_path, commit_msg, params=frozenset(['status=NEW']), cc_list=frozenset([]), submit=False, submit_later=False, step_test_data_create_change=None, step_test_data_submit_change=None):**
Update a set of files by creating and submitting a Gerrit CL. Update a set of files by creating and submitting a Gerrit CL.
...@@ -367,6 +367,10 @@ Args: ...@@ -367,6 +367,10 @@ Args:
* submit_later: If this change has related CLs, we may want to commit * submit_later: If this change has related CLs, we may want to commit
them in a chain. So only set Bot-Commit+1, making it ready for them in a chain. So only set Bot-Commit+1, making it ready for
submit together. Ignored if submit is True. submit together. Ignored if submit is True.
* step_test_data_create_change: Optional mock test data for the step
create gerrit change.
* step_test_data_submit_change: Optional mock test data for the step
submit gerrit change.
Returns: Returns:
A ChangeInfo dictionary as documented here: A ChangeInfo dictionary as documented here:
......
...@@ -325,7 +325,9 @@ class GerritApi(recipe_api.RecipeApi): ...@@ -325,7 +325,9 @@ class GerritApi(recipe_api.RecipeApi):
params=frozenset(['status=NEW']), params=frozenset(['status=NEW']),
cc_list=frozenset([]), cc_list=frozenset([]),
submit=False, submit=False,
submit_later=False): submit_later=False,
step_test_data_create_change=None,
step_test_data_submit_change=None):
"""Update a set of files by creating and submitting a Gerrit CL. """Update a set of files by creating and submitting a Gerrit CL.
Args: Args:
...@@ -342,6 +344,10 @@ class GerritApi(recipe_api.RecipeApi): ...@@ -342,6 +344,10 @@ class GerritApi(recipe_api.RecipeApi):
* submit_later: If this change has related CLs, we may want to commit * submit_later: If this change has related CLs, we may want to commit
them in a chain. So only set Bot-Commit+1, making it ready for them in a chain. So only set Bot-Commit+1, making it ready for
submit together. Ignored if submit is True. submit together. Ignored if submit is True.
* step_test_data_create_change: Optional mock test data for the step
create gerrit change.
* step_test_data_submit_change: Optional mock test data for the step
submit gerrit change.
Returns: Returns:
A ChangeInfo dictionary as documented here: A ChangeInfo dictionary as documented here:
...@@ -368,7 +374,12 @@ class GerritApi(recipe_api.RecipeApi): ...@@ -368,7 +374,12 @@ class GerritApi(recipe_api.RecipeApi):
command.extend(['-p', p]) command.extend(['-p', p])
for cc in cc_list: for cc in cc_list:
command.extend(['--cc', cc]) command.extend(['--cc', cc])
step_result = self('create change at (%s %s)' % (project, branch), command) step_test_data = step_test_data_create_change or (
lambda: self.test_api.update_files_response_data())
step_result = self('create change at (%s %s)' % (project, branch),
command,
step_test_data=step_test_data)
change = int(step_result.json.output.get('_number')) change = int(step_result.json.output.get('_number'))
step_result.presentation.links['change %d' % step_result.presentation.links['change %d' %
change] = '%s/#/q/%d' % (host, change) change] = '%s/#/q/%d' % (host, change)
...@@ -431,5 +442,9 @@ class GerritApi(recipe_api.RecipeApi): ...@@ -431,5 +442,9 @@ class GerritApi(recipe_api.RecipeApi):
'--json_file', '--json_file',
self.m.json.output(), self.m.json.output(),
] ]
step_result = self('submit change %d' % change, submit_cmd) step_test_data = step_test_data_submit_change or (
lambda: self.test_api.update_files_response_data(status='MERGED'))
step_result = self('submit change %d' % change,
submit_cmd,
step_test_data=step_test_data)
return step_result.json.output return step_result.json.output
...@@ -154,6 +154,7 @@ ...@@ -154,6 +154,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
...@@ -203,6 +204,7 @@ ...@@ -203,6 +204,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
...@@ -355,6 +357,7 @@ ...@@ -355,6 +357,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
...@@ -413,6 +416,7 @@ ...@@ -413,6 +416,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
...@@ -462,6 +466,7 @@ ...@@ -462,6 +466,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
...@@ -588,6 +593,7 @@ ...@@ -588,6 +593,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
...@@ -686,6 +692,7 @@ ...@@ -686,6 +692,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
......
...@@ -12,6 +12,7 @@ class GerritTestApi(recipe_test_api.RecipeTestApi): ...@@ -12,6 +12,7 @@ class GerritTestApi(recipe_test_api.RecipeTestApi):
# Exemplary change. Note: This contains only a subset of the key/value pairs # Exemplary change. Note: This contains only a subset of the key/value pairs
# present in production to limit recipe simulation output. # present in production to limit recipe simulation output.
data = { data = {
'id': 'fully~qualified~changeid',
'status': 'NEW', 'status': 'NEW',
'created': '2017-01-30 13:11:20.000000000', 'created': '2017-01-30 13:11:20.000000000',
'_number': str(change_number), '_number': str(change_number),
......
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
...@@ -188,6 +189,7 @@ ...@@ -188,6 +189,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
......
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
...@@ -188,6 +189,7 @@ ...@@ -188,6 +189,7 @@
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@", "@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@", "@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@", "@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"id\": \"fully~qualified~changeid\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@", "@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment