def test_create_ticket_request_failed(self, mock_session): mock_session.return_value = FakeSession(status_code=202) ticket = rt.RTTicket(URL, PROJECT) error_message = '202 Could not create ticket.' request_result = ticket._create_ticket_request('') self.assertEqual(request_result, FAILURE_RESULT._replace(error_message=error_message))
def test_change_status_unexpected_response(self, mock_session): mock_session.return_value = FakeSession(status_code=401) ticket = rt.RTTicket(URL, PROJECT, ticket_id=TICKET_ID) request_result = ticket.change_status('') self.assertEqual( request_result, FAILURE_RESULT._replace(error_message='', url=TICKET_URL))
def test_create_ticket_request(self, mock_session, mock_url): mock_session.return_value = FakeSession(status_code=201) ticket = rt.RTTicket(URL, PROJECT) request_result = ticket._create_ticket_request('') self.assertEqual(request_result, SUCCESS_RESULT._replace(url=None)) self.assertEqual(ticket.ticket_id, '007') self.assertEqual(ticket.ticket_url, mock_url.return_value)
def test_add_attachment(self, mock_session, mock_open): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT, ticket_id=TICKET_ID) request_result = ticket.add_attachment('file_name') self.assertEqual( request_result, SUCCESS_RESULT._replace(ticket_content={'header': ['200 OK']}))
def test_add_attachment_unexpected_response(self, mock_session, mock_open): mock_session.return_value = FakeSession(status_code=401) ticket = rt.RTTicket(URL, PROJECT, ticket_id=TICKET_ID) request_result = ticket.add_attachment('file_name') self.assertEqual( request_result, FAILURE_RESULT._replace(error_message='', url=TICKET_URL))
def test_change_status(self, mock_session): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT, ticket_id=TICKET_ID) request_result = ticket.change_status('') self.assertEqual( request_result, SUCCESS_RESULT._replace(ticket_content={'header': ['200 OK']}))
def test_create_no_subject(self, mock_session): mock_session.return_value = FakeSession() error_message = "subject is a necessary parameter for ticket creation" ticket = rt.RTTicket(URL, PROJECT) request_result = ticket.create(None, TEXT, assignee='me') self.assertEqual(request_result, FAILURE_RESULT._replace(error_message=error_message))
def test_get_ticket_content_unexpected_response(self, mock_session): mock_session.return_value = FakeSession(status_code=404) error_message = "Error getting ticket content" with patch.object(rt.RTTicket, '_verify_project'): ticket = rt.RTTicket(URL, PROJECT) self.assertEqual(ticket.get_ticket_content(TICKET_ID), FAILURE_RESULT._replace(error_message=error_message))
def test_get_ticket_content(self, mock_session): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT) t = ticket.get_ticket_content(TICKET_ID) self.assertEqual( t, SUCCESS_RESULT._replace(url=None, ticket_content={'header': ['200 OK']}))
def test_create_requests_session_tuple_auth(self, mock_session): mock_session.return_value = FakeSession() auth = ('me', 'unbreakablepassword') params = {'user': '******', 'pass': '******'} with patch.object(rt.RTTicket, '_create_requests_session'): ticket = rt.RTTicket(URL, PROJECT, auth=auth) session = ticket._create_requests_session() self.assertEqual(ticket.principal, 'me') self.assertEqual(session.params, params)
def test_create_requests_session_kerberos_auth(self, mock_session, mock_principal, mock_auth): mock_session.return_value = FakeSession() with patch.object(rt.RTTicket, '_create_requests_session'): ticket = rt.RTTicket(URL, PROJECT, auth='kerberos') session = ticket._create_requests_session() self.assertEqual(ticket.principal, mock_principal.return_value) self.assertEqual(session.auth, mock_auth.return_value) self.assertEqual(session.verify, False)
def test_add_attachment_ioerror(self, mock_session): mock_session.return_value = FakeSession() error_message = 'File file_name not found' ticket = rt.RTTicket(URL, PROJECT, ticket_id=TICKET_ID) request_result = ticket.add_attachment('file_name') self.assertEqual( request_result, FAILURE_RESULT._replace(error_message=error_message, url=TICKET_URL))
def test_add_comment_bad_request(self, mock_session, mock_id): mock_session.return_value = FakeSession(status_code=400) error_message = '400 Bad Request' ticket = rt.RTTicket(URL, PROJECT, ticket_id=TICKET_ID) request_result = ticket.add_comment('') self.assertEqual( request_result, FAILURE_RESULT._replace(error_message=error_message, url=TICKET_URL))
def test_change_status_syntax_error(self, mock_session): mock_session.return_value = FakeSession(status_code=409) error_message = '409 Syntax Error' ticket = rt.RTTicket(URL, PROJECT, ticket_id=TICKET_ID) request_result = ticket.change_status('') self.assertEqual( request_result, FAILURE_RESULT._replace(error_message=error_message, url=TICKET_URL))
def test_add_attachment_bad_error(self, mock_session, mock_open): mock_session.return_value = FakeSession(status_code=202) error_message = '202 Could not create ticket.' ticket = rt.RTTicket(URL, PROJECT, ticket_id=TICKET_ID) request_result = ticket.add_attachment('file_name') self.assertEqual( request_result, FAILURE_RESULT._replace(error_message=error_message, url=TICKET_URL))
def test_create_ticket_parameters(self, mock_session, mock_fields): mock_session.return_value = FakeSession() fields = {'assignee': 'me'} mock_fields.return_value = fields content = 'Queue: {0}\nRequestor: {1}\nSubject: {2}\nText: {3} \n'.format( PROJECT, None, SUBJECT, TEXT) content += 'Assignee: me\n' ticket = rt.RTTicket(URL, PROJECT) ticket.principal = None params = ticket._create_ticket_parameters(SUBJECT, TEXT, fields) self.assertDictEqual(params, {'content': content})
def test_create_requests_session_unexpected_response(self, mock_session): mock_session.return_value = FakeSession(status_code=401) with patch.object(rt.RTTicket, '_create_requests_session'): ticket = rt.RTTicket(URL, PROJECT) self.assertFalse(ticket._create_requests_session())
def test_add_attachment_no_ticket_id(self, mock_session): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT) request_result = ticket.add_attachment('file_name') self.assertEqual(request_result, FAILURE_RESULT)
def test_change_status(self, mock_session): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT, ticket_id=TICKET_ID) request_result = ticket.change_status('') self.assertEqual(request_result, SUCCESS_RESULT)
def test_verify_ticket_id_not_valid(self, mock_session): mock_session.return_value = FakeSession(status_code=400) ticket = rt.RTTicket(URL, PROJECT) self.assertFalse(ticket._verify_ticket_id(TICKET_ID))
def test_generate_ticket_url_no_id(self, mock_session): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT) self.assertEqual(None, ticket._generate_ticket_url()) self.assertEqual(ticket.request_result, SUCCESS_RESULT._replace(url=None))
def test_verify_project(self, mock_session): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT) self.assertTrue(ticket._verify_project(PROJECT))
def test_verify_ticket_id_unexpected_response(self, mock_session): mock_session.return_value = FakeSession(status_code=404) with patch.object(rt.RTTicket, '_verify_project'): ticket = rt.RTTicket(URL, PROJECT) self.assertFalse(ticket._verify_ticket_id(TICKET_ID))
def test_get_ticket_content_id_not_valid(self, mock_session): mock_session.return_value = FakeSession(status_code=400) error_message = "Ticket {0} is not valid".format(TICKET_ID) ticket = rt.RTTicket(URL, PROJECT) self.assertEqual(ticket.get_ticket_content(TICKET_ID), FAILURE_RESULT._replace(error_message=error_message))
def test_create(self, mock_session, mock_parameters, mock_request): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT) request_result = ticket.create(SUBJECT, TEXT, assignee='me') mock_parameters.assert_called_with(SUBJECT, TEXT, {'assignee': 'me'}) self.assertEqual(request_result, mock_request.return_value)
def test_change_status_no_ticket_id(self, mock_session): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT) request_result = ticket.change_status('') self.assertEqual(request_result, FAILURE_RESULT)
def test_generate_ticket_url(self, mock_session): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT, ticket_id=TICKET_ID) self.assertEqual(TICKET_URL, ticket._generate_ticket_url()) self.assertEqual(ticket.request_result, SUCCESS_RESULT)
def test_verify_project_not_valid(self, mock_session): mock_session.return_value = FakeSession(status_code=204) with patch.object(rt.RTTicket, '_verify_project'): ticket = rt.RTTicket(URL, PROJECT) self.assertFalse(ticket._verify_project(PROJECT))
def test_create_ticket_request_unexpected_response(self, mock_session): mock_session.return_value = FakeSession(status_code=401) ticket = rt.RTTicket(URL, PROJECT) request_result = ticket._create_ticket_request('') self.assertEqual(request_result, FAILURE_RESULT._replace(error_message=''))
def test_verify_ticket_id(self, mock_session): mock_session.return_value = FakeSession() ticket = rt.RTTicket(URL, PROJECT) self.assertTrue(ticket._verify_ticket_id(TICKET_ID))