def get_issue(datafile, statusfile): cachedir = tempfile.mkdtemp(prefix='ansibot_tests_') try: issue = IssueMock(datafile) issue.html_url = issue.html_url.replace('issues', 'pull') repo = RepoMock() repo.repo_path = 'ansible/ansible' iw = IssueWrapper(repo=repo, cachedir=cachedir, issue=issue) # disable this completely iw.load_update_fetch = lambda x: [] iw.load_update_fetch_rest = lambda x: [] # hook in here to avoid github api calls iw._get_timeline = lambda: issue.events iw._commits = issue.commits # pre-load status to avoid github api calls with open(statusfile, 'rb') as status: iw._pr_status = json.loads(status.read()) # pre-create history to avoid github api calls history = HistoryWrapper(iw, cachedir=cachedir, usecache=False) iw._history = history # merge_commits(self, commits) if issue.commits: iw._history.merge_commits(issue.commits) yield iw finally: shutil.rmtree(cachedir)
def test_owner_pr_submitter_is_not_maintainer_of_all_updated_files(self): """ PR updates 2 files below module_utils, submitter is a maintainer from only one: ensure owner_pr isn't set """ BOTMETA = u""" --- macros: modules: lib/ansible/modules module_utils: lib/ansible/module_utils files: $module_utils/foo/bar.py: maintainers: ElsA Oliver $module_utils/baz/bar.py: maintainers: TiTi ZaZa """ module_indexer = create_indexer(textwrap.dedent(BOTMETA), {}) self.assertEqual(len(module_indexer.modules), 1) # ensure only fake data are loaded self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/module_utils/foo/bar.py'][u'maintainers']), [u'ElsA', u'Oliver']) self.assertEqual(sorted(module_indexer.botmeta[u'files'][u'lib/ansible/module_utils/baz/bar.py'][u'maintainers']), [u'TiTi', u'ZaZa']) CM = ComponentMatcherMock() CM.expected_results = [ { u'repo_filename': u'lib/ansible/module_utils/foo/bar.py', u'labels': [], u'support': None, u'maintainers': [u'ElsA', u'Oliver'], u'notify': [u'ElsA', u'Oliver'], u'ignore': [], }, { u'repo_filename': u'lib/ansible/modules/baz/bar.py', u'labels': [], u'support': None, u'maintainers': [u'TiTi', u'ZaZa'], u'notify': [u'TiTi', u'ZaZa'], u'ignore': [], } ] issue = IssueMock(u'/dev/null') issue.user.login = u'ElsA' issue.html_url = u'https://github.com/ansible/ansible/pull/123' iw = IssueWrapper(cachedir="", issue=issue) iw.pr_files = [ MockFile(u'lib/ansible/module_utils/foo/bar.py'), MockFile(u'lib/ansible/module_utils/baz/bar.py') ] iw.file_indexer = FileIndexerMock() iw.repo = MockRepo(repo_path='ansible/ansible') meta = self.meta.copy() iw._commits = [] meta.update(get_component_match_facts(iw, CM, [])) facts = get_shipit_facts(iw, meta, module_indexer, core_team=[u'bcoca', u'mscherer'], botnames=[u'ansibot']) self.assertEqual(iw.submitter, u'ElsA') self.assertFalse(facts[u'owner_pr'])
def test_owner_pr_submitter_is_maintainer_one_module_utils_file_updated( self): """ Submitter is a maintainer: ensure owner_pr is set (only one file below module_utils updated) """ BOTMETA = """ --- macros: modules: lib/ansible/modules module_utils: lib/ansible/module_utils files: $module_utils/foo/bar.py: maintainers: ElsA Oliver """ modules = {'lib/ansible/module_utils/foo/bar.py': None} module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules) self.assertEqual(len(module_indexer.modules), 2) # ensure only fake data are loaded self.assertEqual( sorted(module_indexer.botmeta['files'] ['lib/ansible/module_utils/foo/bar.py']['maintainers']), ['ElsA', 'Oliver']) issue = IssueMock('/dev/null') issue.user.login = '******' issue.html_url = 'https://github.com/ansible/ansible/pull/123' iw = IssueWrapper(cachedir="", issue=issue) iw.pr_files = [MockFile('lib/ansible/module_utils/foo/bar.py')] # need to give the wrapper a list of known files to compare against iw.file_indexer = FileIndexerMock() # predefine what the matcher is going to return CM = ComponentMatcherMock() CM.expected_results = [{ 'repo_filename': 'lib/ansible/module_utils/foo/bar.py', 'labels': [], 'support': None, 'maintainers': ['ElsA', 'Oliver'], 'notify': ['ElsA', 'Oliver'], 'ignore': [], }] meta = self.meta.copy() meta.update( get_component_match_facts(iw, meta, CM, FileIndexerMock(), module_indexer, [])) facts = get_shipit_facts(iw, meta, module_indexer, core_team=['bcoca', 'mscherer'], botnames=['ansibot']) self.assertEqual(iw.submitter, 'ElsA') self.assertTrue(facts['owner_pr'])
def test_owner_pr_submitter_is_not_maintainer_of_all_updated_files(self): """ PR updates 2 files below module_utils, submitter is a maintainer from only one: ensure owner_pr isn't set """ botmeta_files = { 'lib/ansible/module_utils/foo/bar.py': { 'maintainers': ['ElsA', 'Oliver'] }, 'lib/ansible/module_utils/baz/bar.py': { 'maintainers': ['TiTi', 'ZaZa'] }, } CM = ComponentMatcherMock() CM.expected_results = [{ 'repo_filename': 'lib/ansible/module_utils/foo/bar.py', 'labels': [], 'support': None, 'maintainers': ['ElsA', 'Oliver'], 'notify': ['ElsA', 'Oliver'], 'ignore': [], }, { 'repo_filename': 'lib/ansible/modules/baz/bar.py', 'labels': [], 'support': None, 'maintainers': ['TiTi', 'ZaZa'], 'notify': ['TiTi', 'ZaZa'], 'ignore': [], }] issue = IssueMock('/dev/null') issue.user.login = '******' issue.html_url = 'https://github.com/ansible/ansible/pull/123' cachedir = tempfile.mkdtemp() gh = GithubWrapperMock() iw = IssueWrapper(cachedir=cachedir, issue=issue, github=gh) iw.pr_files = [ MockFile('lib/ansible/module_utils/foo/bar.py'), MockFile('lib/ansible/module_utils/baz/bar.py') ] iw.gitrepo = GitRepoWrapperMock() iw.repo = MockRepo(repo_path='ansible/ansible') meta = self.meta.copy() iw._commits = [] meta.update(get_component_match_facts(iw, CM, [])) facts = get_shipit_facts(iw, meta, botmeta_files, core_team=['bcoca', 'mscherer'], botnames=['ansibot']) shutil.rmtree(cachedir) self.assertEqual(iw.submitter, 'ElsA') self.assertFalse(facts['owner_pr'])
def test_owner_pr_submitter_is_not_maintainer_of_all_updated_files(self): """ PR updates 2 files below module_utils, submitter is a maintainer from only one: ensure owner_pr isn't set """ BOTMETA = """ --- macros: modules: lib/ansible/modules module_utils: lib/ansible/module_utils files: $module_utils/foo/bar.py: maintainers: ElsA Oliver $module_utils/baz/bar.py: maintainers: TiTi ZaZa """ module_indexer = create_indexer(textwrap.dedent(BOTMETA), {}) self.assertEqual(len(module_indexer.modules), 1) # ensure only fake data are loaded self.assertEqual( sorted(module_indexer.botmeta['files'] ['lib/ansible/module_utils/foo/bar.py']['maintainers']), ['ElsA', 'Oliver']) self.assertEqual( sorted(module_indexer.botmeta['files'] ['lib/ansible/module_utils/baz/bar.py']['maintainers']), ['TiTi', 'ZaZa']) issue = IssueMock('/dev/null') issue.user.login = '******' issue.html_url = 'https://github.com/ansible/ansible/pull/123' iw = IssueWrapper(cachedir="", issue=issue) iw.pr_files = [ MockFile('lib/ansible/module_utils/foo/bar.py'), MockFile('lib/ansible/module_utils/baz/bar.py') ] meta = self.meta.copy() meta.update( get_component_match_facts(iw, {}, FileIndexerMock(), module_indexer, [])) facts = get_shipit_facts(iw, meta, module_indexer, core_team=['bcoca', 'mscherer'], botnames=['ansibot']) self.assertEqual(iw.submitter, 'ElsA') self.assertFalse(facts['owner_pr'])
def get_triagermock_for_datafile(datafile): im = IssueMock(datafile) iw = IssueWrapper(repo=None, issue=im) triage = TriageIssuesMock(verbose=True) triage.issue = iw triage.issue.get_events() triage.issue.get_comments() # add additional mock data from fixture triage.force = True triage._now = im.ydata.get('_now', datetime.now()) triage.number = im.ydata.get('number', 1) triage.github_repo = im.ydata.get('github_repo', 'core') triage.match = im.ydata.get('_match') triage.module_indexer.match = im.ydata.get('_match') if not im.ydata.get('_match'): triage.module_indexer.modules = {'xyz': SAMPLE_MODULE} else: triage.module_indexer.modules = {'NULL': triage.module_indexer.match} if im.ydata.get('_match'): triage._module = triage.match.get('name') else: triage._module = None triage._ansible_members = im.ydata.get('_ansible_members', []) triage._module_maintainers = im.ydata.get('_module_maintainers', []) return triage
def test_owner_pr_submitter_is_maintainer_one_module_utils_file_updated( self): """ Submitter is a maintainer: ensure owner_pr is set (only one file below module_utils updated) """ BOTMETA = """ --- macros: modules: lib/ansible/modules module_utils: lib/ansible/module_utils files: $module_utils/foo/bar.py: maintainers: ElsA Oliver """ modules = {'lib/ansible/module_utils/foo/bar.py': None} module_indexer = create_indexer(textwrap.dedent(BOTMETA), modules) self.assertEqual(len(module_indexer.modules), 2) # ensure only fake data are loaded self.assertEqual( sorted(module_indexer.botmeta['files'] ['lib/ansible/module_utils/foo/bar.py']['maintainers']), ['ElsA', 'Oliver']) issue = IssueMock('/dev/null') issue.user.login = '******' issue.html_url = 'https://github.com/ansible/ansible/pull/123' iw = IssueWrapper(cachedir="", issue=issue) iw.pr_files = [MockFile('lib/ansible/module_utils/foo/bar.py')] meta = self.meta.copy() meta.update( get_component_match_facts(iw, None, FileIndexerMock(), module_indexer, [])) facts = get_shipit_facts(iw, meta, module_indexer, core_team=['bcoca', 'mscherer'], botnames=['ansibot']) self.assertEqual(iw.submitter, 'ElsA') self.assertTrue(facts['owner_pr'])
def iw_fixture(request): iw_param = { 'issue': IssueMock(request.param['path']), 'expects': request.param['expected_result'] } return iw_param