mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Provide step_test_data in gerrit.get_revision_info.
This will reduce the need to manually mock steps: calls to get revision info will now return CLs that match the requested change and patchset numbers. Manually mocking will only be required if specific values for other field are desired or if the test case should not have revision info that matches the change and patchset. Change-Id: Ibc6ec62100616680e36d9a842449ac9c6fb2440b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2765162 Commit-Queue: Garrett Beaty <gbeaty@chromium.org> Commit-Queue: Josip Sokcevic <sokcevic@google.com> Auto-Submit: Garrett Beaty <gbeaty@chromium.org> Reviewed-by: Josip Sokcevic <sokcevic@google.com>
This commit is contained in:
@@ -68,7 +68,7 @@ class GerritApi(recipe_api.RecipeApi):
|
||||
revision = step_result.json.output.get('revision')
|
||||
return revision
|
||||
|
||||
def get_change_description(self, host, change, patchset):
|
||||
def get_change_description(self, host, change, patchset, step_test_data=None):
|
||||
"""Gets the description for a given CL and patchset.
|
||||
|
||||
Args:
|
||||
@@ -79,10 +79,10 @@ class GerritApi(recipe_api.RecipeApi):
|
||||
Returns:
|
||||
The description corresponding to given CL and patchset.
|
||||
"""
|
||||
ri = self.get_revision_info(host, change, patchset)
|
||||
ri = self.get_revision_info(host, change, patchset, step_test_data)
|
||||
return ri['commit']['message']
|
||||
|
||||
def get_revision_info(self, host, change, patchset):
|
||||
def get_revision_info(self, host, change, patchset, step_test_data=None):
|
||||
"""
|
||||
Returns the info for a given patchset of a given change.
|
||||
|
||||
@@ -97,11 +97,16 @@ class GerritApi(recipe_api.RecipeApi):
|
||||
"""
|
||||
assert int(change), change
|
||||
assert int(patchset), patchset
|
||||
cls = self.get_changes(
|
||||
host,
|
||||
query_params=[('change', str(change))],
|
||||
o_params=['ALL_REVISIONS', 'ALL_COMMITS'],
|
||||
limit=1)
|
||||
|
||||
step_test_data = step_test_data or (
|
||||
lambda: self.test_api.get_one_change_response_data(change_number=change,
|
||||
patchset=patchset))
|
||||
|
||||
cls = self.get_changes(host,
|
||||
query_params=[('change', str(change))],
|
||||
o_params=['ALL_REVISIONS', 'ALL_COMMITS'],
|
||||
limit=1,
|
||||
step_test_data=step_test_data)
|
||||
cl = cls[0] if len(cls) == 1 else {'revisions': {}}
|
||||
for ri in cl['revisions'].values():
|
||||
# TODO(tandrii): add support for patchset=='current'.
|
||||
|
||||
@@ -210,7 +210,7 @@
|
||||
"~followup_annotations": [
|
||||
"@@@STEP_LOG_LINE@json.output@[@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ {@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"_number\": \"91827\", @@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"_number\": \"123\", @@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"branch\": \"main\", @@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
|
||||
@@ -300,26 +300,7 @@
|
||||
"infra_step": true,
|
||||
"name": "gerrit changes (3)",
|
||||
"~followup_annotations": [
|
||||
"@@@STEP_LOG_LINE@json.output@[@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ {@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"_number\": \"91827\", @@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"branch\": \"main\", @@@",
|
||||
"@@@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@ \"has_review_started\": false, @@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"_number\": \"1\", @@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"commit\": {@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"message\": \"Change commit message\"@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ }@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ }@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ }, @@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"status\": \"NEW\", @@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ \"subject\": \"Change title\"@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@ }@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@]@@@",
|
||||
"@@@STEP_LOG_LINE@json.output@[]@@@",
|
||||
"@@@STEP_LOG_END@json.output@@@"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -54,7 +54,10 @@ def RunSteps(api):
|
||||
|
||||
with api.step.defer_results():
|
||||
api.gerrit.get_change_description(
|
||||
host, change=122, patchset=3)
|
||||
host,
|
||||
change=122,
|
||||
patchset=3,
|
||||
step_test_data=api.gerrit.test_api.get_empty_changes_response_data)
|
||||
|
||||
|
||||
def GenTests(api):
|
||||
|
||||
@@ -5,29 +5,33 @@
|
||||
from recipe_engine import recipe_test_api
|
||||
|
||||
|
||||
# Exemplary change. Note: This contains only a subset of the key/value pairs
|
||||
# present in production to limit recipe simulation output.
|
||||
EXAMPLE_CHANGE = {
|
||||
'status': 'NEW',
|
||||
'created': '2017-01-30 13:11:20.000000000',
|
||||
'_number': '91827',
|
||||
'change_id': 'Ideadbeef',
|
||||
'project': 'chromium/src',
|
||||
'has_review_started': False,
|
||||
'branch': 'main',
|
||||
'subject': 'Change title',
|
||||
'revisions': {
|
||||
'184ebe53805e102605d11f6b143486d15c23a09c': {
|
||||
'_number': '1',
|
||||
'commit': {
|
||||
'message': 'Change commit message',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
class GerritTestApi(recipe_test_api.RecipeTestApi):
|
||||
|
||||
@staticmethod
|
||||
def _gerrit_change_data(change_number=91827, patchset=1, **kwargs):
|
||||
# Exemplary change. Note: This contains only a subset of the key/value pairs
|
||||
# present in production to limit recipe simulation output.
|
||||
data = {
|
||||
'status': 'NEW',
|
||||
'created': '2017-01-30 13:11:20.000000000',
|
||||
'_number': str(change_number),
|
||||
'change_id': 'Ideadbeef',
|
||||
'project': 'chromium/src',
|
||||
'has_review_started': False,
|
||||
'branch': 'main',
|
||||
'subject': 'Change title',
|
||||
'revisions': {
|
||||
'184ebe53805e102605d11f6b143486d15c23a09c': {
|
||||
'_number': str(patchset),
|
||||
'commit': {
|
||||
'message': 'Change commit message',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
data.update(kwargs)
|
||||
return data
|
||||
|
||||
def _make_gerrit_response_json(self, data):
|
||||
return self.m.json.output(data)
|
||||
|
||||
@@ -45,14 +49,10 @@ class GerritTestApi(recipe_test_api.RecipeTestApi):
|
||||
})
|
||||
|
||||
def get_one_change_response_data(self, **kwargs):
|
||||
change = EXAMPLE_CHANGE.copy()
|
||||
change.update(kwargs)
|
||||
return self._make_gerrit_response_json([change])
|
||||
return self._make_gerrit_response_json([self._gerrit_change_data(**kwargs)])
|
||||
|
||||
def get_empty_changes_response_data(self):
|
||||
return self._make_gerrit_response_json([])
|
||||
|
||||
def get_move_change_response_data(self, **kwargs):
|
||||
change = EXAMPLE_CHANGE.copy()
|
||||
change.update(kwargs)
|
||||
return self._make_gerrit_response_json([change])
|
||||
return self._make_gerrit_response_json([self._gerrit_change_data(**kwargs)])
|
||||
|
||||
Reference in New Issue
Block a user