def test_initialize_repo_name_github(self, mock_d, mock_u): """ This tests 'initialize' function where we want to sync an individual repo for GitHub """ # Set up return values mock_u.pagure_issues.return_value = ['mock_issue_pagure'] mock_u.github_issues.return_value = ['mock_issue_github'] # Call the function m.initialize_issues(self.mock_config, repo_name='key_github') # Assert everything was called correctly mock_u.github_issues.assert_called_with('key_github', self.mock_config) mock_u.pagure_issues.assert_not_called() mock_d.sync_with_jira.assert_called_with('mock_issue_github', self.mock_config)
def test_initialize_errors(self, mock_d, mock_u): """ This tests 'initialize' function where syncing with JIRA throws an exception """ # Set up return values mock_u.pagure_issues.return_value = ['mock_issue_pagure'] mock_u.github_issues.return_value = ['mock_issue_github'] mock_d.sync_with_jira.side_effect = Exception() # Call the function with self.assertRaises(Exception): m.initialize_issues(self.mock_config) # Assert everything was called correctly mock_u.pagure_issues.assert_called_with('key_pagure', self.mock_config) mock_d.sync_with_jira.assert_any_call('mock_issue_pagure', self.mock_config)
def test_initialize(self, mock_d, mock_u): """ This tests 'initialize' function where everything goes smoothly! """ # Set up return values mock_u.pagure_issues.return_value = ['mock_issue_pagure'] mock_u.github_issues.return_value = ['mock_issue_github'] # Call the function m.initialize_issues(self.mock_config) # Assert everything was called correctly mock_u.pagure_issues.assert_called_with('key_pagure', self.mock_config) mock_u.github_issues.assert_called_with('key_github', self.mock_config) mock_d.sync_with_jira.assert_any_call('mock_issue_pagure', self.mock_config) mock_d.sync_with_jira.assert_any_call('mock_issue_github', self.mock_config)
def handle_event(): """ Handler for when a user wants to sync a repo """ response = request.form synced_repos = [] for repo_name, switch in response.items(): if switch == "on": # Sync repo_name log.info(f"Starting sync for repo: {repo_name}") initialize_issues(config, repo_name=repo_name) initialize_pr(config, repo_name=repo_name) synced_repos.append(repo_name) if synced_repos: return render_template('sync-page-success.jinja', synced_repos=synced_repos, url=f"http://{REDIRECT_URL}") else: return render_template('sync-page-failure.jinja', url=f"http://{REDIRECT_URL}")
def test_initialize_github_error(self, mock_report_failure, mock_sleep, mock_d, mock_u): """ This tests 'initialize' where we get a GitHub API (not limit) error. """ # Set up return values mock_error = MagicMock(side_effect=Exception('Random Error')) mock_u.pagure_issues.return_value = ['mock_issue_pagure'] mock_u.github_issues.side_effect = mock_error # Call the function with self.assertRaises(Exception): m.initialize_issues(self.mock_config, testing=True) # Assert everything was called correctly mock_u.pagure_issues.assert_called_with('key_pagure', self.mock_config) mock_d.sync_with_jira.assert_any_call('mock_issue_pagure', self.mock_config) mock_u.github_issues.assert_called_with('key_github', self.mock_config) mock_sleep.assert_not_called() mock_report_failure.assert_called_with(self.mock_config)
def test_initialize_api_limit(self, mock_report_failure, mock_sleep, mock_d, mock_u): """ This tests 'initialize' where we get an GitHub API limit error. """ # Set up return values mock_error = MagicMock( side_effect=Exception('API rate limit exceeded')) mock_u.pagure_issues.return_value = ['mock_issue_pagure'] mock_u.github_issues.side_effect = mock_error # Call the function m.initialize_issues(self.mock_config, testing=True) # Assert everything was called correctly mock_u.pagure_issues.assert_called_with('key_pagure', self.mock_config) mock_d.sync_with_jira.assert_any_call('mock_issue_pagure', self.mock_config) mock_u.github_issues.assert_called_with('key_github', self.mock_config) mock_sleep.assert_called_with(3600) mock_report_failure.assert_not_called()