def test_bad_2(self): # Change log has multiple issues. self.changelog_cfg.return_value = True self.labels.return_value = [] self.issues.return_value = ['One issue', 'OMG another one'] self.comment_ids.return_value = [] expected = (CHANGELOG_PROLOGUE.format(user='******') + CHANGELOG_BAD_LIST + '* {0}\n'.format('One issue') + '* {0}\n'.format('OMG another one') + CHANGELOG_BAD_EPILOGUE + CHANGELOG_EPILOGUE) with app.app_context(): process_changelog_consistency('repo', '1234', 'installation') assert self.issues.call_count == 1 self.submit_comment.assert_called_with(expected, comment_id=None, return_url=True) self.set_status.assert_called_with( 'failure', 'There were failures in checks - see ' 'comments by @stsci-bot above', 'stsci-bot', target_url='url')
def test_bad_1(self): # Change log has 1 issue. self.changelog_cfg.return_value = True self.labels.return_value = [] self.issues.return_value = ['One issue'] self.comment_ids.return_value = ['123'] expected = (CHANGELOG_PROLOGUE.format(user='******') + CHANGELOG_BAD_LIST + '* {0}\n'.format('One issue') + CHANGELOG_BAD_EPILOGUE) expected = (expected.replace('issues with', 'issue with').replace( 'fix these', 'fix this')) expected += CHANGELOG_EPILOGUE with app.app_context(): process_changelog_consistency('repo', '1234', 'installation') assert self.issues.call_count == 1 self.submit_comment.assert_called_with(expected, comment_id='123', return_url=True) self.set_status.assert_called_with( 'failure', 'There were failures in checks - see ' 'comments by @astropy-bot above', 'astropy-bot', target_url='url')
def test_config_noop(self): # Repo does not want any changelog check. self.changelog_cfg.return_value = False with app.app_context(): process_changelog_consistency('repo', '1234', 'installation') assert self.issues.call_count == 0
def test_warn_comment_exists(self): # Time is beyond warn deadline but within close deadline. There is # already a warning, so don't do anything. self.open_pull_requests.return_value = ['123'] self.last_commit_date.return_value = now() - 230 self.find_comments.return_value = ['1'] with app.app_context(): process_pull_requests('repo', 'installation') assert self.submit_comment.call_count == 0 assert self.close.call_count == 0
def test_keep_open(self): # Time is before warn deadline so don't do anything. self.open_pull_requests.return_value = ['123'] self.last_commit_date.return_value = now() - 210 self.find_comments.return_value = [] with app.app_context(): process_pull_requests('repo', 'installation') assert self.find_comments.call_count == 0 assert self.submit_comment.call_count == 0 assert self.close.call_count == 0
def test_keep_open(self): # Time is before warn deadline so don't do anything. self.get_issues.return_value = ['123'] self.get_label_added_date.return_value = now() - 14000 self.find_comments.return_value = [] with app.app_context(): process_issues('repo', 'installation') assert self.find_comments.call_count == 0 assert self.submit_comment.call_count == 0 assert self.close.call_count == 0
def test_warn_comment_exists(self): # Time is beyond warn deadline but within close deadline. There is # already a warning, so don't do anything. self.get_issues.return_value = ['123'] self.get_label_added_date.return_value = now() - 34400 self.find_comments.return_value = ['1'] with app.app_context(): list(process_issues('repo', 'installation')) assert self.submit_comment.call_count == 0 assert self.close.call_count == 0 assert self.set_labels.call_count == 0
def test_close_noclose(self): # Time is beyond close deadline, and there is no comment yet but the # YAML says don't autoclose. self.autoclose_stale.return_value = False self.open_pull_requests.return_value = ['123'] self.last_commit_date.return_value = now() - 241 self.find_comments.return_value = [] with app.app_context(): process_pull_requests('repo', 'installation') assert self.submit_comment.call_count == 0 assert self.close.call_count == 0
def test_close_comment_exists(self): # Time is beyond close deadline, and there is already a comment. In this # case no new comment should be posted and the issue should be kept open # since this likely indicates the issue was open again manually. self.open_pull_requests.return_value = ['123'] self.last_commit_date.return_value = now() - 241 self.find_comments.return_value = ['1'] self.labels.return_value = ['io.fits', 'Bug'] with app.app_context(): process_pull_requests('repo', 'installation') assert self.submit_comment.call_count == 0 assert self.close.call_count == 0
def test_warn(self): # Time is beyond warn deadline but within close deadline. There isn't a # comment yet, so a comment should be posted. self.open_pull_requests.return_value = ['123'] self.last_commit_date.return_value = now() - 230 self.find_comments.return_value = [] with app.app_context(): process_pull_requests('repo', 'installation') assert self.submit_comment.call_count == 1 expected = PULL_REQUESTS_CLOSE_WARNING.format(pasttime='3 minutes', futuretime='20 seconds') self.submit_comment.assert_called_with(expected) assert self.close.call_count == 0
def test_close(self): # Time is beyond close deadline, and there is no comment yet so the # closing comment can be posted and the issue closed. self.open_pull_requests.return_value = ['123'] self.last_commit_date.return_value = now() - 241 self.find_comments.return_value = [] with app.app_context(): process_pull_requests('repo', 'installation') assert self.submit_comment.call_count == 1 expected = PULL_REQUESTS_CLOSE_EPILOGUE self.submit_comment.assert_called_with(expected) assert self.close.call_count == 1
def test_close(self): # Time is beyond close deadline, and there is no comment yet so the # closing comment can be posted and the issue closed. self.get_issues.return_value = ['123'] self.get_label_added_date.return_value = now() - 34443 self.find_comments.return_value = [] with app.app_context(): process_issues('repo', 'installation') assert self.submit_comment.call_count == 1 expected = ISSUE_CLOSE_EPILOGUE self.submit_comment.assert_called_with(expected) assert self.close.call_count == 1
def test_close_keep_open_label(self): # Time is beyond close deadline, and there is no comment yet but there # is a keep-open label self.open_pull_requests.return_value = ['123'] self.last_commit_date.return_value = now() - 241 self.find_comments.return_value = [] with app.app_context(): with patch.object(app, 'stale_pull_requests_close', False): process_pull_requests('repo', 'installation') assert self.submit_comment.call_count == 1 expected = PULL_REQUESTS_CLOSE_WARNING.format(pasttime='4 minutes', futuretime='20 seconds') self.submit_comment.assert_called_with(expected) assert self.close.call_count == 0
def test_warn(self): # Time is beyond warn deadline but within close deadline. There isn't a # comment yet, so a comment should be posted. self.get_issues.return_value = ['123'] self.get_label_added_date.return_value = now() - 34400 self.find_comments.return_value = [] with app.app_context(): process_issues('repo', 'installation') assert self.submit_comment.call_count == 1 expected = ISSUE_CLOSE_WARNING.format(pasttime='9 hours ago', futuretime='5 hours') self.submit_comment.assert_called_with(expected) assert self.close.call_count == 0
def test_close_disabled(self): # Time is beyond close deadline, and there is no comment yet but the # global option to allow closing has not been enabled. Since there is no # comment, the warning gets posted (rather than the 'epilogue') self.open_pull_requests.return_value = ['123'] self.last_commit_date.return_value = now() - 241 self.find_comments.return_value = [] with app.app_context(): with patch.object(app, 'stale_pull_requests_close', False): process_pull_requests('repo', 'installation') assert self.submit_comment.call_count == 1 expected = PULL_REQUESTS_CLOSE_WARNING.format(pasttime='4 minutes', futuretime='20 seconds') self.submit_comment.assert_called_with(expected) assert self.close.call_count == 0
def test_close_comment_exists(self): # Time is beyond close deadline, and there is already a comment. In this # case no new comment should be posted and the issue should be kept open # since this likely indicates the issue was open again manually. self.get_issues.return_value = ['123'] self.get_label_added_date.return_value = now() - 34443 self.find_comments.return_value = ['1'] with app.app_context(): process_issues('repo', 'installation') self.get_issues.assert_called_with('open', 'Close?') self.get_label_added_date.assert_called_with('Close?') assert self.submit_comment.call_count == 0 assert self.close.call_count == 0
def test_close_disabled(self): # Second case: time is beyond close deadline, and there is no comment yet # but the global option to allow closing has not been enabled. Since there # is no comment, the warning gets posted (rather than the 'epilogue') self.get_issues.return_value = ['123'] self.get_label_added_date.return_value = now() - 34443 self.find_comments.return_value = [] with app.app_context(): with patch.object(app, 'stale_issue_close', False): process_issues('repo', 'installation') assert self.submit_comment.call_count == 1 expected = ISSUE_CLOSE_WARNING.format(pasttime='9 hours ago', futuretime='5 hours') self.submit_comment.assert_called_with(expected) assert self.close.call_count == 0
def test_good(self): # Change log has no issue. self.changelog_cfg.return_value = True self.labels.return_value = [] self.issues.return_value = [] self.comment_ids.return_value = ['123', '456'] expected = (CHANGELOG_PROLOGUE.format(user='******') + CHANGELOG_GOOD + CHANGELOG_EPILOGUE) with app.app_context(): process_changelog_consistency('repo', '1234', 'installation') assert self.issues.call_count == 1 self.submit_comment.assert_called_with(expected, comment_id='456', return_url=True) self.set_status.assert_called_with('success', 'All checks passed', 'stsci-bot', target_url='url')
def test_experimental(self): # Pull request is experimental. Don't check change log yet but # leave a comment. self.changelog_cfg.return_value = True self.labels.return_value = ['Experimental'] expected = ( CHANGELOG_PROLOGUE.format(user='******') + CHANGELOG_NOT_DONE.format( status='an experimental', is_done='discussion in settled') + CHANGELOG_EPILOGUE) with app.app_context(): process_changelog_consistency('repo', '1234', 'installation') assert self.issues.call_count == 0 self.submit_comment.assert_called_with(expected, comment_id=None, return_url=True) self.set_status.assert_called_with( 'failure', 'There were failures in checks - see ' 'comments by @astropy-bot above', 'astropy-bot', target_url='url')
def test_work_in_progress(self): # Pull request is work in progress. Don't check change log yet but # leave a comment. self.changelog_cfg.return_value = True self.labels.return_value = ['Work in progress'] expected = (CHANGELOG_PROLOGUE.format(user='******') + CHANGELOG_NOT_DONE.format(status='a work in progress', is_done='is ready for review') + CHANGELOG_EPILOGUE) with app.app_context(): process_changelog_consistency('repo', '1234', 'installation') assert self.issues.call_count == 0 self.submit_comment.assert_called_with(expected, comment_id=None, return_url=True) self.set_status.assert_called_with( 'failure', 'There were failures in checks - see ' 'comments by @stsci-bot above', 'stsci-bot', target_url='url')