Exemplo n.º 1
0
 def test_add_issue_watchers(self, mock_get_users: Mock,
                             mock_get_issue_properties: Mock,
                             mock_JIRA_client: Mock) -> None:
     mock_JIRA_client.return_value.create_issue.return_value = self.mock_issue
     mock_get_users.return_value = [self.mock_user]
     mock_get_issue_properties.return_value = self.mock_issue_instance
     mock_labels = ['mock-label']
     with app.test_request_context():
         jira_client = JiraClient(
             issue_labels=mock_labels,
             issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
             issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
             issue_tracker_password=app.config['ISSUE_TRACKER_PASSWORD'],
             issue_tracker_project_id=app.
             config['ISSUE_TRACKER_PROJECT_ID'],
             issue_tracker_max_results=app.
             config['ISSUE_TRACKER_MAX_RESULTS'])
         jira_client.create_issue(description='desc',
                                  owner_ids=['*****@*****.**'],
                                  frequent_user_ids=[],
                                  priority_level='P2',
                                  project_key='',
                                  table_uri='key',
                                  title='title',
                                  table_url='http://table')
         mock_JIRA_client.return_value.add_watcher.assert_called_with(
             issue=self.mock_issue.key, watcher='test')
Exemplo n.º 2
0
 def test_create_returns_JIRAError(self, mock_get_users: Mock,
                                   mock_JIRA_client: Mock) -> None:
     mock_JIRA_client.return_value.create_issue.side_effect = JIRAError(
         'Some exception')
     with app.test_request_context():
         mock_get_users.return_value = [self.mock_user]
         try:
             jira_client = JiraClient(
                 issue_labels=[],
                 issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
                 issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
                 issue_tracker_password=app.
                 config['ISSUE_TRACKER_PASSWORD'],
                 issue_tracker_project_id=app.
                 config['ISSUE_TRACKER_PROJECT_ID'],
                 issue_tracker_max_results=app.
                 config['ISSUE_TRACKER_MAX_RESULTS'])
             jira_client.create_issue(description='desc',
                                      owner_ids=['test_email'],
                                      frequent_user_ids=['test_email'],
                                      priority_level='P2',
                                      project_key='',
                                      table_uri='key',
                                      title='title',
                                      table_url='http://table')
         except JIRAError as e:
             self.assertTrue(type(e), type(JIRAError))
             self.assertTrue(e, 'Some exception')
Exemplo n.º 3
0
 def test_get_issues_returns_issues(self, mock_sort_issues: Mock,
                                    mock_get_url: Mock,
                                    mock_get_issue_properties: Mock,
                                    mock_JIRA_client: Mock) -> None:
     mock_JIRA_client.return_value.search_issues.return_value = self.mock_jira_issues
     mock_get_issue_properties.return_value = self.mock_issue
     mock_get_url.return_value = 'url'
     mock_sort_issues.return_value = [self.mock_issue]
     with app.test_request_context():
         jira_client = JiraClient(
             issue_labels=[],
             issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
             issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
             issue_tracker_password=app.config['ISSUE_TRACKER_PASSWORD'],
             issue_tracker_project_id=app.
             config['ISSUE_TRACKER_PROJECT_ID'],
             issue_tracker_max_results=app.
             config['ISSUE_TRACKER_MAX_RESULTS'])
         results = jira_client.get_issues(table_uri='key')
         mock_JIRA_client.assert_called()
         self.assertEqual(results.issues[0], self.mock_issue)
         self.assertEqual(results.total, self.mock_jira_issues.total)
         mock_JIRA_client.return_value.search_issues.assert_has_calls([
             call(SEARCH_STUB_ALL_ISSUES.format(table_key="key"),
                  maxResults=3),
             call(SEARCH_STUB_OPEN_ISSUES.format(table_key="key"),
                  maxResults=1)
         ])
 def test_create_issue(self, mock_get_issue_properties: Mock,
                       mock_JIRA_client: Mock) -> None:
     mock_JIRA_client.return_value.create_issue.return_value = self.mock_issue
     mock_get_issue_properties.return_value = self.mock_issue_instance
     with app.test_request_context():
         jira_client = JiraClient(
             issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
             issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
             issue_tracker_password=app.config['ISSUE_TRACKER_PASSWORD'],
             issue_tracker_project_id=app.
             config['ISSUE_TRACKER_PROJECT_ID'],
             issue_tracker_max_results=app.
             config['ISSUE_TRACKER_MAX_RESULTS'])
         results = jira_client.create_issue(description='desc',
                                            table_uri='key',
                                            title='title')
         mock_JIRA_client.assert_called
         self.assertEqual(results, self.mock_issue_instance)
         mock_JIRA_client.return_value.create_issue.assert_called_with(
             fields=dict(
                 project={'id': app.config["ISSUE_TRACKER_PROJECT_ID"]},
                 issuetype={
                     'id': 1,
                     'name': 'Bug',
                 },
                 summary='title',
                 description='desc' + ' \n Reported By: [email protected]' +
                 ' \n Table Key: ' + 'key [PLEASE DO NOT REMOVE]',
                 reporter={'name': 'test'}))
Exemplo n.º 5
0
 def test__generate_all_issues_url_no_issues(self, mock_JIRA_client: Mock) -> None:
     with app.test_request_context():
         jira_client = JiraClient(issue_labels=[],
                                  issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
                                  issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
                                  issue_tracker_password=app.config['ISSUE_TRACKER_PASSWORD'],
                                  issue_tracker_project_id=app.config['ISSUE_TRACKER_PROJECT_ID'],
                                  issue_tracker_max_results=app.config['ISSUE_TRACKER_MAX_RESULTS'])
         issues: List[DataIssue]
         issues = []
         url = jira_client._generate_all_issues_url(table_uri="table", issues=issues)
         self.assertEqual(url, '')
Exemplo n.º 6
0
 def test__generate_all_issues_url(self, mock_url_lib: Mock, mock_JIRA_client: Mock) -> None:
     mock_url_lib.return_value = 'test'
     with app.test_request_context():
         jira_client = JiraClient(issue_labels=[],
                                  issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
                                  issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
                                  issue_tracker_password=app.config['ISSUE_TRACKER_PASSWORD'],
                                  issue_tracker_project_id=app.config['ISSUE_TRACKER_PROJECT_ID'],
                                  issue_tracker_max_results=app.config['ISSUE_TRACKER_MAX_RESULTS'])
         issues = [DataIssue(issue_key='key', title='title', url='url', status='open', priority='Major')]
         url = jira_client._generate_all_issues_url(table_uri="table", issues=issues)
         self.assertEqual(url, 'test_url/issues/?jql=test')
Exemplo n.º 7
0
 def test_get_issues_returns_JIRAError(self, mock_remaining_issues: Mock, mock_JIRA_client: Mock) -> None:
     mock_JIRA_client.return_value.get_issues.side_effect = JIRAError('Some exception')
     mock_remaining_issues.return_value = 0
     with app.test_request_context():
         try:
             jira_client = JiraClient(issue_labels=[],
                                      issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
                                      issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
                                      issue_tracker_password=app.config['ISSUE_TRACKER_PASSWORD'],
                                      issue_tracker_project_id=app.config['ISSUE_TRACKER_PROJECT_ID'],
                                      issue_tracker_max_results=app.config['ISSUE_TRACKER_MAX_RESULTS'])
             jira_client.get_issues('key')
         except JIRAError as e:
             self.assertTrue(type(e), type(JIRAError))
             self.assertTrue(e, 'Some exception')
Exemplo n.º 8
0
 def test_create_issue_with_inactive_owner(self, mock_get_users: Mock,
                                           mock_get_issue_properties: Mock,
                                           mock_JIRA_client: Mock) -> None:
     mock_JIRA_client.return_value.create_issue.return_value = self.mock_issue
     mock_get_users.return_value = [self.mock_inactive_user]
     mock_get_issue_properties.return_value = self.mock_issue_instance
     mock_labels = ['mock-label']
     with app.test_request_context():
         jira_client = JiraClient(
             issue_labels=mock_labels,
             issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
             issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
             issue_tracker_password=app.config['ISSUE_TRACKER_PASSWORD'],
             issue_tracker_project_id=app.
             config['ISSUE_TRACKER_PROJECT_ID'],
             issue_tracker_max_results=app.
             config['ISSUE_TRACKER_MAX_RESULTS'])
         results = jira_client.create_issue(
             description='desc',
             owner_ids=['*****@*****.**'],
             frequent_user_ids=['*****@*****.**'],
             priority_level='P2',
             project_key='',
             table_uri='key',
             title='title',
             table_url='http://table')
         mock_JIRA_client.assert_called()
         self.assertEqual(results, self.mock_issue_instance)
         mock_JIRA_client.return_value.create_issue.assert_called_with(
             fields=dict(
                 project={'id': app.config["ISSUE_TRACKER_PROJECT_ID"]},
                 issuetype={
                     'id': 1,
                     'name': 'Bug',
                 },
                 labels=mock_labels,
                 summary='title',
                 description=
                 ("desc \n "
                  "*Reported By:* [email protected] \n "
                  "*Table Key:* key [PLEASE DO NOT REMOVE] \n "
                  "*Table URL:* http://table \n\n "
                  "*Owners (added as Watchers):* \n "
                  "Table Owners:\n "
                  "test_full_name (Alumni) \u2022 Manager: test_manager_name "
                  ),
                 priority={'name': 'Major'},
                 reporter={'name': 'test'}))
Exemplo n.º 9
0
 def test__generate_issues_url(self, mock_url_lib: Mock,
                               mock_JIRA_client: Mock) -> None:
     mock_url_lib.return_value = 'test'
     with app.test_request_context():
         jira_client = JiraClient(
             issue_labels=[],
             issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
             issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
             issue_tracker_password=app.config['ISSUE_TRACKER_PASSWORD'],
             issue_tracker_project_id=app.
             config['ISSUE_TRACKER_PROJECT_ID'],
             issue_tracker_max_results=app.
             config['ISSUE_TRACKER_MAX_RESULTS'])
         url = jira_client._generate_issues_url(search_stub="search",
                                                table_uri="table",
                                                issueCount=1)
         self.assertEqual(url, 'test_url/issues/?jql=test')
 def test_create_returns_JIRAError(self, mock_JIRA_client: Mock) -> None:
     mock_JIRA_client.return_value.create_issue.side_effect = JIRAError(
         'Some exception')
     with app.test_request_context():
         try:
             jira_client = JiraClient(
                 issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
                 issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
                 issue_tracker_password=app.
                 config['ISSUE_TRACKER_PASSWORD'],
                 issue_tracker_project_id=app.
                 config['ISSUE_TRACKER_PROJECT_ID'],
                 issue_tracker_max_results=app.
                 config['ISSUE_TRACKER_MAX_RESULTS'])
             jira_client.create_issue(description='desc',
                                      table_uri='key',
                                      title='title')
         except JIRAError as e:
             self.assertTrue(type(e), type(JIRAError))
             self.assertTrue(e, 'Some exception')
 def test_get_issues_returns_issues(self, mock_get_url: Mock,
                                    mock_get_issue_properties: Mock,
                                    mock_JIRA_client: Mock) -> None:
     mock_JIRA_client.return_value.search_issues.return_value = self.mock_jira_issues
     mock_get_issue_properties.return_value = self.mock_issue
     mock_get_url.return_value = 'url'
     with app.test_request_context():
         jira_client = JiraClient(
             issue_tracker_url=app.config['ISSUE_TRACKER_URL'],
             issue_tracker_user=app.config['ISSUE_TRACKER_USER'],
             issue_tracker_password=app.config['ISSUE_TRACKER_PASSWORD'],
             issue_tracker_project_id=app.
             config['ISSUE_TRACKER_PROJECT_ID'],
             issue_tracker_max_results=app.
             config['ISSUE_TRACKER_MAX_RESULTS'])
         results = jira_client.get_issues(table_uri='key')
         mock_JIRA_client.assert_called
         self.assertEqual(results.issues[0], self.mock_issue)
         self.assertEqual(results.remaining, self.mock_jira_issues.total)
         mock_JIRA_client.return_value.search_issues.assert_called_with(
             'text ~ "key" AND resolution = Unresolved order by createdDate DESC',
             maxResults=3)
Exemplo n.º 12
0
    def test_create_JiraClient_validates_config(self, mock_JIRA_client: Mock) -> None:
        with app.test_request_context():
            try:

                JiraClient(issue_labels=[],
                           issue_tracker_url='',
                           issue_tracker_user='',
                           issue_tracker_password='',
                           issue_tracker_project_id=-1,
                           issue_tracker_max_results=-1)
            except IssueConfigurationException as e:
                self.assertTrue(type(e), type(IssueConfigurationException))
                self.assertTrue(e, 'The following config settings must be set for Jira: '
                                   'ISSUE_TRACKER_URL, ISSUE_TRACKER_USER, ISSUE_TRACKER_PASSWORD, '
                                   'ISSUE_TRACKER_PROJECT_ID')