def _MkPatch(self, source, sha1, ref='refs/heads/master', **kwargs): json = self.test_json remote = kwargs.pop('remote', site_config.params.EXTERNAL_REMOTE) url_prefix = kwargs.pop('url_prefix', site_config.params.EXTERNAL_GERRIT_URL) suppress_branch = kwargs.pop('suppress_branch', False) change_id = kwargs.pop('ChangeId', None) if change_id is None: change_id = self.MakeChangeId() json.update(kwargs) change_num, patch_num = _GetNumber(), _GetNumber() # Note we intentionally use a gerrit like refspec here; we want to # ensure that none of our common code pathways puke on a non head/tag. refspec = gerrit.GetChangeRef(change_num + 1000, patch_num) json['currentPatchSet'].update( dict(number=patch_num, ref=refspec, revision=sha1)) json['branch'] = os.path.basename(ref) json['_unittest_url_bypass'] = source json['id'] = change_id obj = self.patch_kls(json.copy(), remote, url_prefix) self.assertEqual(obj.patch_dict, json) self.assertEqual(obj.remote, remote) self.assertEqual(obj.url_prefix, url_prefix) self.assertEqual(obj.project, json['project']) self.assertEqual(obj.ref, refspec) self.assertEqual(obj.change_id, change_id) self.assertEqual(obj.id, '%s%s~%s~%s' % ( site_config.params.CHANGE_PREFIX[remote], json['project'], json['branch'], change_id)) # Now make the fetching actually work, if desired. if not suppress_branch: # Note that a push is needed here, rather than a branch; branch # will just make it under refs/heads, we want it literally in # refs/changes/ self._run(['git', 'push', source, '%s:%s' % (sha1, refspec)], source) return obj
from chromite.lib import gerrit from chromite.lib import git from chromite.lib import osutils from chromite.lib import patch as cros_patch import mock _GetNumber = iter(itertools.count()).next FAKE_PATCH_JSON = { "project": "tacos/chromite", "branch": "master", "id": "Iee5c89d929f1850d7d4e1a4ff5f21adda800025f", "currentPatchSet": { "number": "2", "ref": gerrit.GetChangeRef(1112, 2), "revision": "ff10979dd360e75ff21f5cf53b7f8647578785ef", }, "number": "1112", "subject": "chromite commit", "owner": { "name": "Chromite Master", "email": "*****@*****.**" }, "url": "http://gerrit.chromium.org/gerrit/1112", "lastUpdated": 1311024529, "sortKey": "00166e8700001052", "open": True, "status": "NEW", }
from chromite.lib import osutils from chromite.lib import patch as cros_patch site_config = config_lib.GetConfig() _GetNumber = iter(itertools.count()).next FAKE_PATCH_JSON = { 'project': 'tacos/chromite', 'branch': 'master', 'id': 'Iee5c89d929f1850d7d4e1a4ff5f21adda800025f', 'currentPatchSet': { 'number': '2', 'ref': gerrit.GetChangeRef(1112, 2), 'revision': 'ff10979dd360e75ff21f5cf53b7f8647578785ef', }, 'number': '1112', 'subject': 'chromite commit', 'owner': { 'name': 'Chromite Master', 'email': '*****@*****.**', }, 'url': 'https://chromium-review.googlesource.com/1112', 'lastUpdated': 1311024529, 'sortKey': '00166e8700001052', 'open': True, 'status': 'NEW', }