def testAddPatchesToManifestWithInvalidTokens(self): """Tests to add a fake patch with invalid tokens to a manifest. Test whether _AddPatchesToManifest will skip commits with invalid tokens. """ with TemporaryManifest() as f: gerrit_patch = cros_patch.GerritFetchOnlyPatch( 'https://host/chromite/tacos', 'chromite/tacos', 'refs/changes/11/12345/4', 'master', 'cros-internal', '7181e4b5e182b6f7d68461b04253de095bad74f9', 'I47ea30385af60ae4cc2acc5d1a283a46423bc6e1', '12345', '4', '*****@*****.**', 1, 1, 3, #Invalid tokens '…') mock_pool = self._MockValidationPool([gerrit_patch]) self.manager._AddPatchesToManifest(f.name, mock_pool) new_doc = minidom.parse(f.name) self.assertEqual( 0, len( new_doc.getElementsByTagName( lkgm_manager.PALADIN_COMMIT_ELEMENT))) self.assertEqual(1, mock_pool.SendNotification.call_count) self.assertEqual(1, mock_pool.RemoveReady.call_count)
def testAddPatchesToManifest(self): """Tests whether we can add a fake patch to an empty manifest file. This test creates an empty xml file with just manifest/ tag in it then runs the AddPatchesToManifest with one mocked out GerritPatch and ensures the newly generated manifest has the correct patch information afterwards. """ with TemporaryManifest() as f: gerrit_patch = cros_patch.GerritFetchOnlyPatch( 'https://host/chromite/tacos', 'chromite/tacos', 'refs/changes/11/12345/4', 'master', 'cros-internal', '7181e4b5e182b6f7d68461b04253de095bad74f9', 'I47ea30385af60ae4cc2acc5d1a283a46423bc6e1', '12345', '4', '*****@*****.**', 1, 1, 3) mock_pool = self._MockValidationPool([gerrit_patch]) self.manager._AddPatchesToManifest(f.name, mock_pool) new_doc = minidom.parse(f.name) element = new_doc.getElementsByTagName( lkgm_manager.PALADIN_COMMIT_ELEMENT)[0] self.assertEqual(element.getAttribute(cros_patch.ATTR_CHANGE_ID), gerrit_patch.change_id) self.assertEqual(element.getAttribute(cros_patch.ATTR_COMMIT), gerrit_patch.commit) self.assertEqual(element.getAttribute(cros_patch.ATTR_PROJECT), gerrit_patch.project) self.assertEqual(element.getAttribute(cros_patch.ATTR_REMOTE), gerrit_patch.remote) self.assertEqual(element.getAttribute(cros_patch.ATTR_BRANCH), gerrit_patch.tracking_branch) self.assertEqual(element.getAttribute(cros_patch.ATTR_REF), gerrit_patch.ref) self.assertEqual(element.getAttribute(cros_patch.ATTR_OWNER_EMAIL), gerrit_patch.owner_email) self.assertEqual(element.getAttribute(cros_patch.ATTR_PROJECT_URL), gerrit_patch.project_url) self.assertEqual( element.getAttribute(cros_patch.ATTR_PATCH_NUMBER), gerrit_patch.patch_number) self.assertEqual(element.getAttribute(cros_patch.ATTR_FAIL_COUNT), str(gerrit_patch.fail_count)) self.assertEqual(element.getAttribute(cros_patch.ATTR_PASS_COUNT), str(gerrit_patch.pass_count)) self.assertEqual( element.getAttribute(cros_patch.ATTR_TOTAL_FAIL_COUNT), str(gerrit_patch.total_fail_count))
def testGetAttributeDict(self): """Test Whether GetAttributeDict can get the commit message properly.""" change = cros_patch.GerritFetchOnlyPatch( 'https://host/chromite/tacos', 'chromite/tacos', 'refs/changes/11/12345/4', 'master', 'cros-internal', '7181e4b5e182b6f7d68461b04253de095bad74f9', 'I47ea30385af60ae4cc2acc5d1a283a46423bc6e1', '12345', '4', '*****@*****.**', 1, 1, 3) expected = { cros_patch.ATTR_PROJECT_URL: 'https://host/chromite/tacos', cros_patch.ATTR_PROJECT: 'chromite/tacos', cros_patch.ATTR_REF: 'refs/changes/11/12345/4', cros_patch.ATTR_BRANCH: 'master', cros_patch.ATTR_REMOTE: 'cros-internal', cros_patch.ATTR_COMMIT: '7181e4b5e182b6f7d68461b04253de095bad74f9', cros_patch.ATTR_CHANGE_ID: 'I47ea30385af60ae4cc2acc5d1a283a46423bc6e1', cros_patch.ATTR_GERRIT_NUMBER: '12345', cros_patch.ATTR_PATCH_NUMBER: '4', cros_patch.ATTR_OWNER_EMAIL: '*****@*****.**', cros_patch.ATTR_FAIL_COUNT: '1', cros_patch.ATTR_PASS_COUNT: '1', cros_patch.ATTR_TOTAL_FAIL_COUNT: '3', cros_patch.ATTR_COMMIT_MESSAGE: None} self.assertEqual(change.GetAttributeDict(), expected) self.PatchObject(cros_patch.GitRepoPatch, '_AddFooters', return_value='commit message') change.commit_message = 'commit message' expected[cros_patch.ATTR_COMMIT_MESSAGE] = 'commit message' self.assertEqual(change.GetAttributeDict(), expected)
def testAddPatchesToManifestWithUnicode(self): """Tests to add a fake patch with unicode to an empty manifest file. Test whether _AddPatchesToManifest can add to a patch with unicode to manifest file without any UnicodeError exception and that the decoded manifest has the original unicode string. """ with TemporaryManifest() as f: gerrit_patch = cros_patch.GerritFetchOnlyPatch( 'https://host/chromite/tacos', 'chromite/tacos', 'refs/changes/11/12345/4', 'master', 'cros-internal', '7181e4b5e182b6f7d68461b04253de095bad74f9', 'I47ea30385af60ae4cc2acc5d1a283a46423bc6e1', '12345', '4', u'foo\[email protected]', 1, 1, 3) self.manager._AddPatchesToManifest(f.name, [gerrit_patch]) new_doc = minidom.parse(f.name) element = new_doc.getElementsByTagName( lkgm_manager.PALADIN_COMMIT_ELEMENT)[0] self.assertEqual(element.getAttribute(cros_patch.ATTR_OWNER_EMAIL), gerrit_patch.owner_email)