Ejemplo n.º 1
0
 def test_get_status_id(self, mock_session, mock_url):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket._get_status_id('Abandoned')
     self.assertEqual(request_result, 51)
     request_result = ticket._get_status_id('Blocked')
     self.assertEqual(request_result, None)
Ejemplo n.º 2
0
 def test_create_no_summary(self, mock_session):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT)
     t = ticket.create(None, DESCRIPTION, TYPE)
     error_message = 'summary is a necessary parameter for ticket creation'
     self.assertEqual(t,
                      FAILURE_RESULT._replace(error_message=error_message))
Ejemplo n.º 3
0
 def test_get_status_id_unexpected_response(self, mock_session, mock_url,
                                            mock_verify_project,
                                            mock_verify_ticket_id):
     mock_session.return_value = FakeSession(status_code=401)
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket._get_status_id('Abandoned')
     self.assertEqual(request_result, None)
Ejemplo n.º 4
0
 def test_change_status(self, mock_session, mock_url, mock_get_id,
                        mock_content):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     mock_get_id.return_value = 'STATUS_ID'
     request_result = ticket.change_status('Done')
     self.assertEqual(request_result, mock_content.return_value)
Ejemplo n.º 5
0
    def test_comment_errors(self, mock_session_factoy):
        """
        Test if error responses are handled correctly when adding comments.
        """
        mock_response = Mock()
        mock_response.raise_for_status.side_effect = requests.RequestException(
        )
        mock_response.status_code = 400
        mock_response.json.return_value = {
            "errorMessages": [],
            "errors": {
                "comment": "Comment body can not be empty!"
            }
        }

        mock_session = Mock()
        mock_session.post = Mock(return_value=mock_response)

        mock_session_factoy.return_value = mock_session

        ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)

        # This should not raise `IndexError: list index out of range` when
        # handling error
        ticket.add_comment('foobar')
Ejemplo n.º 6
0
 def test_create_ticket_request_unexpected_response(self, mock_verify,
                                                    mock_session):
     mock_session.return_value = FakeSession(status_code=401)
     ticket = jira.JiraTicket(URL, PROJECT)
     request_result = ticket._create_ticket_request(FIELDS)
     error_message = "Error creating ticket - No internet connection"
     self.assertEqual(request_result,
                      FAILURE_RESULT._replace(error_message=error_message))
Ejemplo n.º 7
0
 def test_create_ticket_request(self, mock_session, mock_url, mock_content):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT)
     mock_url.return_value = 'TICKET_URL'
     request_result = ticket._create_ticket_request(FIELDS)
     self.assertEqual(ticket.ticket_id, 'TICKET_ID')
     self.assertEqual(ticket.ticket_url, 'TICKET_URL')
     self.assertEqual(request_result, mock_content.return_value)
Ejemplo n.º 8
0
 def test_get_ticket_content_unexpected_response(self, mock_session):
     mock_session.return_value = FakeSession(status_code=401)
     error_message = "Error getting ticket content"
     with self.assertRaises(TicketException):
         ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
         t = ticket._verify_ticket_id(ticket_id=TICKET_ID)
         self.assertEqual(
             t, FAILURE_RESULT._replace(error_message=error_message))
Ejemplo n.º 9
0
 def test_generate_ticket_url(self, mock_session):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     self.assertEqual(TICKET_URL, ticket._generate_ticket_url())
     self.assertEqual(
         ticket.request_result,
         SUCCESS_RESULT._replace(url=TICKET_URL,
                                 ticket_content=MOCK_RESULT))
Ejemplo n.º 10
0
 def test_get_ticket_content(self, mock_session):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     t = ticket.get_ticket_content(ticket_id=TICKET_ID)
     self.assertEqual(ticket.ticket_content, MOCK_RESULT)
     self.assertEqual(
         t,
         SUCCESS_RESULT._replace(ticket_content=MOCK_RESULT,
                                 url=TICKET_URL))
Ejemplo n.º 11
0
 def test_add_watcher_empty(self, mock_session, mock_url):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket.add_watcher('')
     error_message = 'Error adding  as a watcher to ticket'
     self.assertEqual(
         request_result,
         RETURN_RESULT('Failure', error_message, mock_url.return_value,
                       MOCK_RESULT, None))
Ejemplo n.º 12
0
 def test_remove_all_watchers(self, mock_session, mock_url, mock_get_list,
                              mock_content):
     mock_session.return_value = FakeSession()
     mock_content.return_value = SUCCESS_RESULT
     watchers = ['me', 'you']
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     mock_get_list.return_value = watchers
     request_result = ticket.remove_all_watchers()
     self.assertEqual(request_result,
                      SUCCESS_RESULT._replace(watchers=watchers))
Ejemplo n.º 13
0
 def test_add_comment_unexpected_response(self, mock_session, mock_url,
                                          mock_verify_project,
                                          mock_verify_ticket_id):
     mock_session.return_value = FakeSession(status_code=401)
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket.add_comment('Status update: ...')
     error_message = "Error adding comment to ticket - No internet connection"
     self.assertEqual(
         request_result,
         RETURN_RESULT('Failure', error_message, mock_url.return_value,
                       None, None))
Ejemplo n.º 14
0
 def test_add_attachment_ioerror(self, mock_session, mock_url,
                                 mock_verify_project,
                                 mock_verify_ticket_id):
     mock_session.return_value = FakeSession(status_code=401)
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket.add_attachment('file_name')
     error_message = "File file_name not found"
     self.assertEqual(
         request_result,
         RETURN_RESULT('Failure', error_message, mock_url.return_value,
                       None, None))
Ejemplo n.º 15
0
 def test_add_watcher_unexpected_response(self, mock_session, mock_url,
                                          mock_verify_project,
                                          mock_verify_ticket_id):
     mock_session.return_value = FakeSession(status_code=401)
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket.add_watcher('me')
     error_message = 'Error adding "me" as a watcher to ticket'
     self.assertEqual(
         request_result,
         RETURN_RESULT('Failure', error_message, mock_url.return_value,
                       None, None))
Ejemplo n.º 16
0
 def test_edit_unexpected_response(self, mock_session, mock_url,
                                   mock_fields, mock_verify_project,
                                   mock_verify_ticket_id):
     mock_session.return_value = FakeSession(status_code=401)
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket.edit(summary='Edited summary')
     error_message = "Error editing ticket - No internet connection"
     self.assertEqual(
         request_result,
         RETURN_RESULT('Failure', error_message, mock_url.return_value,
                       None, None))
Ejemplo n.º 17
0
 def test_change_status_unexpected_response(self, mock_session, mock_url,
                                            mock_verify_project,
                                            mock_verify_ticket_id,
                                            mock_get_id):
     mock_session.return_value = FakeSession(status_code=401)
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket.change_status('Done')
     error_message = "Error changing status of ticket"
     self.assertEqual(
         request_result,
         RETURN_RESULT('Failure', error_message, mock_url.return_value,
                       None, None))
Ejemplo n.º 18
0
 def test_remove_all_watchers_unexpected_response(self, mock_session,
                                                  mock_url,
                                                  mock_verify_project,
                                                  mock_verify_ticket_id,
                                                  mock_get_list):
     mock_session.return_value = FakeSession(status_code=401)
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     mock_get_list.return_value = ['me', 'you']
     request_result = ticket.remove_all_watchers()
     error_message = "Error removing 2 watchers from ticket"
     self.assertEqual(
         request_result,
         RETURN_RESULT('Failure', error_message, mock_url.return_value,
                       None, None))
Ejemplo n.º 19
0
 def test_create_ticket_parameters(self, mock_session, mock_fields):
     mock_fields.return_value = FIELDS
     ticket = jira.JiraTicket(URL, PROJECT)
     params = ticket._create_ticket_parameters(SUMMARY, DESCRIPTION, TYPE,
                                               FIELDS)
     expected_params = {
         'fields': {
             'project': {
                 'key': PROJECT
             },
             'summary': SUMMARY,
             'description': DESCRIPTION,
             'issuetype': {
                 'name': TYPE
             },
             'assignee': 'me'
         }
     }
     self.assertEqual(params, expected_params)
Ejemplo n.º 20
0
 def test_add_attachment_no_ticket_id(self, mock_session):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT)
     request_result = ticket.add_attachment('file_name')
     self.assertEqual(request_result, FAILURE_RESULT)
Ejemplo n.º 21
0
 def test_add_attachment(self, mock_session, mock_url, mock_open,
                         mock_content):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket.add_attachment('file_name')
     self.assertEqual(request_result, mock_content.return_value)
Ejemplo n.º 22
0
 def test_add_comment(self, mock_session, mock_url, mock_content):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket.add_comment('Status update: ...')
     self.assertEqual(request_result, mock_content.return_value)
Ejemplo n.º 23
0
 def test_remove_watcher_no_ticket_id(self, mock_session):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT)
     request_result = ticket.remove_watcher('me')
     self.assertEqual(request_result, FAILURE_RESULT)
Ejemplo n.º 24
0
 def test_get_watchers_list(self, mock_session, mock_url):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket._get_watchers_list()
     self.assertEqual(request_result, ['me', 'you'])
Ejemplo n.º 25
0
 def test_add_comment_no_ticket_id(self, mock_session):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT)
     request_result = ticket.add_comment('Status update: ...')
     self.assertEqual(request_result, FAILURE_RESULT)
Ejemplo n.º 26
0
 def test_edit(self, mock_session, mock_url, mock_fields, mock_content):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket.edit(summary='Edited summary')
     self.assertEqual(request_result, mock_content.return_value)
Ejemplo n.º 27
0
 def test_create(self, mock_session, mock_request, mock_parameters):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT)
     ticket.create(SUMMARY, DESCRIPTION, TYPE)
     mock_parameters.assert_called_once_with(SUMMARY, DESCRIPTION, TYPE, {})
     mock_request.assert_called_once_with(mock_parameters.return_value)
Ejemplo n.º 28
0
 def test_remove_watcher(self, mock_session, mock_url, mock_content):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT, ticket_id=TICKET_ID)
     request_result = ticket.remove_watcher('me')
     self.assertEqual(request_result, mock_content.return_value)
Ejemplo n.º 29
0
 def test_change_status_no_ticket_id(self, mock_session):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT)
     request_result = ticket.change_status('Done')
     self.assertEqual(request_result, FAILURE_RESULT)
Ejemplo n.º 30
0
 def test_edit_no_ticket_id(self, mock_session, mock_fields):
     mock_session.return_value = FakeSession()
     ticket = jira.JiraTicket(URL, PROJECT)
     request_result = ticket.edit(summary='Edited summary')
     self.assertEqual(request_result, FAILURE_RESULT)