def testPatch(self): p = patch.GerritPatch('https://example.com', 672011, '2f0d5c7') other_patch = patch.GerritPatch(u'https://example.com', 672011, '2f0d5c7') self.assertEqual(p, other_patch) self.assertEqual(str(p), '2f0d5c7') self.assertEqual(p.id_string, 'https://example.com/672011/2f0d5c7')
def testAsDict(self): commits = (commit.Commit('chromium', 'aaa7336c82'), commit.Commit('catapult', 'e0a2efbb3d')) p = patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7') c = change.Change(commits, p) expected = { 'commits': [ { 'repository': 'chromium', 'git_hash': 'aaa7336c82', 'url': _CHROMIUM_URL + '/+/aaa7336c82', }, { 'repository': 'catapult', 'git_hash': 'e0a2efbb3d', 'url': _CATAPULT_URL + '/+/e0a2efbb3d', }, ], 'patch': { 'server': 'https://codereview.com', 'change': 672011, 'revision': '2f0d5c7', }, } self.assertEqual(c.AsDict(), expected)
def testFromDictWithAllFields(self, get_change): get_change.return_value = { 'id': 'repo~branch~id', 'revisions': { '2f0d5c7': {} } } c = change.Change.FromDict({ 'commits': ( { 'repository': 'chromium', 'git_hash': 'aaa7336' }, { 'repository': 'catapult', 'git_hash': 'e0a2efb' }, ), 'patch': { 'server': 'https://codereview.com', 'change': 672011, 'revision': '2f0d5c7', }, }) commits = (commit.Commit('chromium', 'aaa7336'), commit.Commit('catapult', 'e0a2efb')) p = patch.GerritPatch('https://codereview.com', 'repo~branch~id', '2f0d5c7') expected = change.Change(commits, p) self.assertEqual(c, expected)
def testAsDict(self, commit_as_dict, patch_as_dict): commit_as_dict.side_effect = ({ 'git_hash': 'aaa7336c82' }, { 'git_hash': 'e0a2efbb3d' }) patch_as_dict.return_value = {'revision': '2f0d5c7'} commits = (commit.Commit('chromium', 'aaa7336c82'), commit.Commit('catapult', 'e0a2efbb3d')) p = patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7') c = change.Change(commits, p) expected = { 'commits': [ { 'git_hash': 'aaa7336c82' }, { 'git_hash': 'e0a2efbb3d' }, ], 'patch': { 'revision': '2f0d5c7' }, } self.assertEqual(c.AsDict(), expected)
def testUpdateWithMultiplePatches(self): base_commit = commit.Commit('chromium', 'aaa7336c821888839f759c6c0a36b56c') p = patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7') c = change.Change((base_commit, ), p) with self.assertRaises(NotImplementedError): c.Update(c)
def testDifferingPatch(self): change_a = change.Change((commit.Commit('chromium', '0e57e2b'),)) change_b = change.Change( (commit.Commit('chromium', 'babe852'),), patch=patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7')) with self.assertRaises(commit.NonLinearError): change.Change.Midpoint(change_a, change_b)
def testAsDict(self): p = patch.GerritPatch('https://example.com', 672011, '2f0d5c7') expected = { 'server': 'https://example.com', 'change': 672011, 'revision': '2f0d5c7', } self.assertEqual(p.AsDict(), expected)
def testFromDictGerrit(self, get_change): get_change.return_value = _GERRIT_CHANGE_INFO p = patch.FromDict('https://example.com/c/repo/+/658277') expected = patch.GerritPatch( 'https://example.com', 'repo~branch~id', 'current revision') self.assertEqual(p, expected)
def testFromDict(self, get_change): get_change.return_value = _GERRIT_CHANGE_INFO p = patch.GerritPatch.FromDict({ 'server': 'https://example.com', 'change': 658277, 'revision': 4, }) expected = patch.GerritPatch( 'https://example.com', 'repo~branch~id', 'other revision') self.assertEqual(p, expected)
def testUpdate(self): old_commit = commit.Commit('chromium', 'aaaaaaaa') dep_a = commit.Commit('catapult', 'e0a2efbb') change_a = change.Change((old_commit, dep_a)) new_commit = commit.Commit('chromium', 'bbbbbbbb') dep_b = commit.Commit('another_repo', 'e0a2efbb') p = patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7') change_b = change.Change((dep_b, new_commit), p) expected = change.Change((new_commit, dep_a, dep_b), p) self.assertEqual(change_a.Update(change_b), expected)
def testBuildParameters(self, get_change): get_change.return_value = _GERRIT_CHANGE_INFO p = patch.GerritPatch('https://example.com', 658277, 'current revision') expected = { 'patch_gerrit_url': 'https://example.com', 'patch_issue': 658277, 'patch_project': 'chromium/src', 'patch_ref': 'refs/changes/77/658277/5', 'patch_repository_url': 'https://googlesource.com/chromium/src', 'patch_set': 5, 'patch_storage': 'gerrit', } self.assertEqual(p.BuildParameters(), expected)
def testAsDict(self, get_change): get_change.return_value = _GERRIT_CHANGE_INFO p = patch.GerritPatch('https://example.com', 658277, 'current revision') expected = { 'server': 'https://example.com', 'change': 658277, 'revision': 'current revision', 'url': 'https://example.com/c/chromium/src/+/658277/5', 'subject': 'Subject', 'author': '*****@*****.**', 'time': '2018-02-01 23:46:56.000000000', } self.assertEqual(p.AsDict(), expected)
def testWithPatch(self, mock_patch): mock_patch.return_value = patch_module.GerritPatch( 'https://lalala', '123', None) request = dict(_BASE_REQUEST) request['patch'] = 'https://lalala/c/foo/bar/+/123' response = self.Post('/api/new', request, status=200) result = json.loads(response.body) self.assertIn('jobId', result) self.assertEqual( result['jobUrl'], 'https://testbed.example.com/job/%s' % result['jobId']) mock_patch.assert_called_with(request['patch']) job = job_module.JobFromId(result['jobId']) self.assertEqual('123', job.gerrit_change_id) self.assertEqual('https://lalala', job.gerrit_server)
def testChange(self): base_commit = commit.Commit('chromium', 'aaa7336c821888839f759c6c0a36b56c') dep = commit.Commit('catapult', 'e0a2efbb3d1a81aac3c90041eefec24f066d26ba') p = patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7') # Also test the deps conversion to frozenset. c = change.Change([base_commit, dep], p) self.assertEqual(c, change.Change((base_commit, dep), p)) string = 'chromium@aaa7336 catapult@e0a2efb + 2f0d5c7' id_string = ('catapult@e0a2efbb3d1a81aac3c90041eefec24f066d26ba ' 'chromium@aaa7336c821888839f759c6c0a36b56c + ' 'https://codereview.com/672011/2f0d5c7') self.assertEqual(str(c), string) self.assertEqual(c.id_string, id_string) self.assertEqual(c.base_commit, base_commit) self.assertEqual(c.last_commit, dep) self.assertEqual(c.deps, (dep,)) self.assertEqual(c.commits, (base_commit, dep)) self.assertEqual(c.patch, p)
def Patch(revision='abc123'): return patch.GerritPatch('https://codereview.com', 'repo~branch~id', revision)
def testPatch_WithNewlines(self): p = patch.GerritPatch('https://example.com', 'abcdef\n', '2f0d5c7\n') self.assertEqual(str(p), '2f0d5c7') self.assertEqual(p.id_string, 'https://example.com/abcdef/2f0d5c7')