def test_jenkins_host(self): """ Test config.get_jenkins_host method """ config = Config({ 'jenkins': { 'url': self.hostname, 'user': '******', 'pass': '******' }, 'repos': [] }) assert config.get_jenkins_url() == self.hostname
def test_push(self): jenkins_mock = mock.MagicMock() handler = GithubEventHandler(Config(self.config), jenkins_mock) with self.__fixture('push.json') as fp: payload = json.load(fp) handler.process_github_event('push', payload) expected_params = { 'repo': 'Wikia/app', 'author': 'Kyle Daigle', 'branch': 'wikia-logger-backtrace-for-errors', 'commit': '4d2ab4e76d0d405d17d1a0f2b8a6071394e3ab40', 'email': '*****@*****.**' } jenkins_mock.build_job.assert_called_once_with( 'job3', expected_params)
def test_pull_request_review_comment(self): jenkins_mock = mock.MagicMock() handler = GithubEventHandler(Config(self.config), jenkins_mock) with self.__fixture('pull_request_review_comment.json') as fp: payload = json.load(fp) handler.process_github_event('pull_request_review_comment', payload) expected_params = { 'repo': 'Wikia/sparrow', 'branch': 'test-branch', 'commit': 'f96bc53e42b40dbbd0ceb19b68a3365e7a66f223', 'pull_num': 31, } jenkins_mock.build_job.assert_called_once_with( 'job5', expected_params)
def test_pull_request_merged_labels(self): jenkins_mock = mock.MagicMock() handler = GithubEventHandler(Config(self.config), jenkins_mock) with self.__fixture('pull_request_merged.json') as fp: payload = json.load(fp) handler.process_github_event('pull_request', payload) expected_params = { 'repo': 'Wikia/ad-engine', 'branch': 'ADEN-6924', 'commit': 'e8f4b7c5a2c40fe14513ce27cc013cd7f779f9cc', 'pull_num': 120, 'labels': 'Major change,Foo' } jenkins_mock.build_job.assert_called_once_with( 'aden-job', expected_params)
def test_extra_job_params(self): jenkins_mock = mock.MagicMock() handler = GithubEventHandler(Config(self.config), jenkins_mock) with self.__fixture('pull_request_other_repo.json') as fp: payload = json.load(fp) handler.process_github_event('pull_request', payload) expected_params = { 'repo': 'Wikia/other', 'branch': 'test-branch', 'commit': 'f96bc53e42b40dbbd0ceb19b68a3365e7a66f223', 'pull_num': 31, 'silent': 'true', 'labels': [] } jenkins_mock.build_job.assert_called_once_with( 'job4', expected_params)
def test_match(self): """ Data provider for config.match method test """ cases = [ { 'repo': 'foo/repo-with-actions', 'branch': 'any-branch', 'target_branch': 'any-target-branch', 'event_type': 'pull_request', 'index': [14, 15], 'action': 'opened' }, { 'repo': 'foo/repo-with-actions', 'branch': 'any-branch', 'target_branch': 'any-target-branch', 'event_type': 'pull_request', 'index': 15, 'action': 'unlabeled' }, { 'repo': 'foo/repo-with-actions', 'branch': 'any-branch', 'target_branch': 'any-target-branch', 'event_type': 'pull_request', 'index': [], 'action': 'any-un-matched-action' }, { 'repo': 'foo/bar', 'branch': 'tests', 'target_branch': 'tests', 'event_type': 'push', 'index': 1 }, { 'repo': 'foo/bar', 'branch': 'foo-feature', 'target_branch': 'foo-feature', 'event_type': 'push', 'index': 2 }, { 'repo': 'foo/tests', 'branch': 'tests', 'target_branch': 'tests', 'event_type': 'push', 'index': None }, { 'repo': 'foo/test2', 'branch': 'tests', 'target_branch': 'tests', 'event_type': 'push', 'index': 4 }, { 'repo': 'foo/tests', 'branch': 'dev', 'target_branch': 'dev', 'event_type': 'push', 'index': 3 }, { 'repo': 'foo/bar', 'branch': 'tests', 'target_branch': 'tests', 'comment': "test @TestTag1", 'event_type': 'push', 'index': [0, 1] }, { 'repo': 'foo/bar', 'branch': 'a-feature', 'target_branch': 'dev', 'comment': 'test @TestTag1', 'event_type': 'pull_request', 'index': [0, 2] }, { 'repo': 'foo/bar', 'branch': 'tests', 'target_branch': 'dev', 'comment': 'test @NonExistent', 'event_type': 'pull_request', 'index': None }, # name/ifnot { 'repo': 'foo/test3', 'branch': 'some-branch', 'target_branch': 'master', 'comment': 'test @NonExistent', 'event_type': 'pull_request', 'index': 6 }, { 'repo': 'foo/test3', 'branch': 'some-branch', 'target_branch': 'master', 'comment': 'test @TestTag3', 'event_type': 'pull_request', 'index': 5 }, # target_branch { 'repo': 'foo/test4', 'branch': 'a-feature', 'target_branch': 'dev', 'comment': 'test @TestTag3', 'event_type': 'pull_request', 'index': None }, { 'repo': 'foo/test4', 'branch': 'a-feature', 'target_branch': 'master', 'comment': 'test @TestTag3', 'event_type': 'pull_request', 'index': [7, 8] }, { 'repo': 'foo/test4', 'branch': 'a-feature', 'target_branch': 'release-001', 'comment': 'test @TestTag3', 'event_type': 'pull_request', 'index': 7 }, # glob patterns { 'repo': 'foo/test5', 'branch': 'glob123xglob', 'target_branch': 'yglob', 'event_type': 'push', 'index': 9 }, { 'repo': 'foo/test5', 'branch': 'glob123sglob', 'target_branch': 'yglob', 'event_type': 'push', 'index': [9, 10] }, { 'repo': 'foo/test5', 'branch': 'xglob', 'target_branch': 'tglob123yglob', 'event_type': 'push', 'index': 11 }, { 'repo': 'foo/test5', 'branch': 'xglob', 'target_branch': 'tglob123sglob', 'event_type': 'push', 'index': [11, 12] }, { 'repo': 'foo/test6', 'branch': 'exact1', 'target_branch': 'exact2', 'event_type': 'push', 'index': 13 }, { 'repo': 'foo/test6', 'branch': 'exact11', 'target_branch': 'exact22', 'event_type': 'push', 'index': None }, ] config = Config({'jenkins': self.jenkins, 'repos': self.repos}) for item in cases: self.check_match(config, item)