def test_all_gerrit_reporters_use_tagged_comment(self): gerrit = GerritConnection('fake_gerrit', {'server': 'localhost', 'user': '******'}) # Fake ssh (stdout, stderr) so the command is returned by review() gerrit._ssh = lambda x: ['', x] errors = [] for pipeline in self.getPipelines(): for action in self.sched._reporter_actions.values(): # Note: when unset: # merge-failure action defaults to failure action # disabled action defaults to success action for reporter in [r for r in getattr(pipeline, action, []) if isinstance(r, GerritReporter)]: cmd = gerrit.review( 'some/project', '12345,42', '%s action on %s pipeline' % (action, pipeline.name), reporter.reporter_config) try: self.assertIn( ' --tag autogenerated:ci ', cmd, 'Pipeline %s action %s must use ' 'tag: autogenerated:ci' % ( pipeline.name, action)) except AssertionError as e: errors.append(str(e)) self.maxDiff = None self.assertListEqual([], errors)
def run_query(self, files, expected_patches, _ssh_mock): gerrit_config = { 'user': '******', 'server': 'localhost', } gerrit = GerritConnection('review_gerrit', gerrit_config) calls, values = read_fixtures(files) _ssh_mock.side_effect = values result = gerrit.simpleQuery('project:openstack-infra/zuul') _ssh_mock.assert_has_calls(calls) self.assertEquals(len(calls), _ssh_mock.call_count, '_ssh should be called %d times' % len(calls)) self.assertIsNotNone(result, 'Result is not none') self.assertEquals(len(result), expected_patches, 'There must be %d patches.' % expected_patches)
def test_postmerge_gerrit_review_command(self): pipe = self.getPipeline('postmerge') # Pick the first Gerrit success reporter gerrit_reporter = [r for r in pipe.success_actions if isinstance(r, GerritReporter)][0] self.assertEquals({}, gerrit_reporter.reporter_config) gerrit = GerritConnection('fake_gerrit', {'server': 'localhost', 'user': '******'}) # Fake ssh (stdout, stderr) so the command is returned by review() gerrit._ssh = lambda x: ['', x] cmd = gerrit.review('some/project', '12345,42', 'hello world') self.longMessage = True self.assertEquals( 'gerrit review --project some/project ' '--message "hello world" 12345,42', cmd, 'gerrit review command does not match Gerrit 2.13 expectation')
def test_postmerge_gerrit_review_command(self): pipe = self.getPipeline('postmerge') # Pick the first Gerrit success reporter gerrit_reporter = [ r for r in pipe.success_actions if isinstance(r, GerritReporter) ][0] self.assertEquals({}, gerrit_reporter.reporter_config) gerrit = GerritConnection('fake_gerrit', { 'server': 'localhost', 'user': '******' }) # Fake ssh (stdout, stderr) so the command is returned by review() gerrit._ssh = lambda x: ['', x] cmd = gerrit.review('some/project', '12345,42', 'hello world') self.longMessage = True self.assertEquals( 'gerrit review --project some/project ' '--message "hello world" 12345,42', cmd, 'gerrit review command does not match Gerrit 2.13 expectation')