Skip to content
Snippets Groups Projects
Commit c1922c54 authored by Robert Habermann's avatar Robert Habermann
Browse files

remove unused test file

parent 0682417d
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
from __future__ import unicode_literals # support both Python2 and 3
#
# Name: test_pyotrs.py
# Description: Test for pyotrs module
#
# Author: robert.habermann@dlh.de
# Date: 2015-07-14
# make sure (early) that parent dir (main app) is in path
import os.path
import sys
current_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(current_path, os.pardir))
import unittest2 as unittest
import responses
import requests
from mock import MagicMock, patch
from pyotrs import Client, Ticket
from pyotrs.lib import NoBaseURL, NoWebServiceName, NoCredentials
from pyotrs.lib import SessionCreateError, SessionIDFileError, OTRSAPIError, OTRSHTTPError
class PyOTRSTests(unittest.TestCase):
""" Test Responses: Check whether direct call to _helper function raises the 'get api'
exception when Error is recvd
"""
# def test_resp___get_json_ticket_data(self):
# with responses.RequestsMock() as rsps:
# # responses will return this data:
# rsps.add(responses.POST,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST/Session',
# body={'SessionID': 'fakesessionid'},
# status=200,
# content_type='application/json')
# rsps.add(responses.GET,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST/Ticket/1',
# body={'Error': {'ErrorMessage': 'TicketGet: Authorization failing!',
# 'ErrorCode' : 'TicketGet.AuthFail'}},
# status=200,
# content_type='application/json')
#
# username = 'wrong_username'
# password = 'wrong_password'
#
# url = 'https://fqdn/otrs/nph-genericinterface.pl/Webservice' \
# '/GenericTicketConnectorREST/Ticket/1'
# payload = {
# 'UserLogin' : username,
# 'Password' : password,
# 'AllArticles' : 0,
# 'DynamicFields': 1
# }
#
# obj = Client('http://localhost/', 'dummy', 'username', 'password')
# obj.session_restore_or_set_up_new()
#
# self.assertRaisesRegexp(OTRSAPIError,
# 'TicketGet API Error.*',
# obj._ticket_get_json,
# url=url,
# payload=payload)
#
# def test_resp_get_json_ticket_data_by_ticket_id(self):
# """ This tests: get_json_ticket_data_by_ticket_id - Test 200 OK;
# Body Error """
# with responses.RequestsMock() as rsps:
# # responses will return this data:
# rsps.add(responses.POST,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST/Session',
# body={'SessionID': 'fakesessionid'},
# status=200,
# content_type='application/json')
# rsps.add(responses.GET,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST/Ticket/1',
# body={'Error': {'ErrorMessage': 'TicketGet: Authorization failing!',
# 'ErrorCode' : 'TicketGet.AuthFail'}},
# status=200,
# content_type='application/json')
#
# username = 'wrong_username'
# password = 'wrong_password'
#
# obj = Client('http://localhost/', 'dummy', 'username', 'password')
# obj.session_restore_or_set_up_new()
# obj.ticket_get_by_id(1)
#
# self.assertEqual({'Error': {'ErrorMessage': 'TicketGet: Authorization failing!',
# 'ErrorCode' : 'TicketGet.AuthFail'}},
# obj.response.json())
# self.assertEqual(200, obj.response.status_code)
#
# def test_resp_update_by_ticket_id_set_title_valid(self):
# """ This tests: Test Responses: update title on valid ticket """
# with responses.RequestsMock() as rsps:
# # responses will return this data:
# rsps.add(responses.POST,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST/Session',
# body={'SessionID': 'fakesessionid'},
# status=200,
# content_type='application/json'
# )
# rsps.add(responses.PATCH,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST/Ticket/10',
# body={'TicketNumber': '1970010100000010',
# 'TicketID' : '10'},
# status=200,
# content_type='application/json')
#
# username = 'fake_username'
# password = 'fake_password'
#
# obj = Client('http://localhost/', 'dummy', 'username', 'password')
# obj.session_restore_or_set_up_new()
# obj.ticket_update_set_title(10, 'Full New Title')
#
# self.assertEqual({'TicketNumber': '1970010100000010', 'TicketID': '10'},
# obj.response.json())
# self.assertEqual(200, obj.response.status_code)
#
# def test_resp_update_by_ticket_id_set_title_invalid(self):
# """ This tests: Test Responses: update title on invalid ticket (or wrong credentials) """
# # responses will return this data:
# with responses.RequestsMock() as rsps:
# rsps.add(responses.POST,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST/Session',
# body={'SessionID': 'fakesessionid'},
# status=200,
# content_type='application/json')
# rsps.add(responses.PATCH,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST/Ticket/20',
# body={'Error': {'ErrorCode' : 'TicketUpdate.AccessDenied',
# 'ErrorMessage': 'TicketUpdate: User does not have access '
# 'to the ticket!'}},
# status=200,
# content_type='application/json')
#
# username = 'fake_username'
# password = 'fake_password'
#
# obj = Client('http://localhost/', 'dummy', 'username', 'password')
# obj.session_restore_or_set_up_new()
# obj.ticket_update_set_title(20, 'Full New Title')
#
# self.assertEqual({'Error': {'ErrorCode' : 'TicketUpdate.AccessDenied',
# 'ErrorMessage': 'TicketUpdate: User does not have access '
# 'to the ticket!'}},
# obj.response.json())
# self.assertEqual(200, obj.response.status_code)
#
# def test_mock_get_json_ticket_data_by_ticket_id(self):
# """ This tests: Test Mock: Validate that the right call to _get_json_ticket_data
# is made by requests when calling: get_json_ticket_data_by_ticket_id
# """
# with responses.RequestsMock() as rsps:
# rsps.add(responses.POST,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST/Session',
# body={'UserLogin': 'wrong_username',
# 'Password': 'wrong_password'},
# status=200,
# content_type='application/json')
# # Define values for function call
# username = 'wrong_username'
# password = 'wrong_password'
#
# # Define data that should be called later:
# url = 'https://fqdn/otrs/nph-genericinterface.pl/Webservice' \
# '/GenericTicketConnectorREST/Ticket/1'
# payload = {
# 'SessionID': 'fakesessionid',
# 'AllArticles': 0,
# 'DynamicFields': 1
# }
#
# # create object
# obj = Client('http://fqdn/', 'GenericTicketConnectorREST', username, password)
# obj.session_create()
# enable Mock
# obj._ticket_get_json = MagicMock()
# call function
# obj.ticket_get_by_id(1)
#
# def test_mock_get_json_ticket_data_by_ticket_id_with(self):
# """ This tests: Test Mock: Validate that the right call to requests is made """
# with responses.RequestsMock() as rsps:
# rsps.add(responses.POST,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST/Session',
# body={'SessionID': 'fakesessionid'},
# status=200,
# content_type='application/json')
# # expected content of request:
# mock_url = 'https://fqdn/otrs/nph-genericinterface.pl/Webservice' \
# '/GenericTicketConnectorREST/Ticket/1'
# mock_payload = {
# 'SessionID' : 'fakesessionid',
# 'AllArticles' : 0,
# 'DynamicFields': 1
# }
#
# mock_username = 'wrong_username'
# mock_password = 'wrong_password'
#
# obj = Client('http://localhost/', 'dummy', 'username', 'password')
# obj.session_restore_or_set_up_new()
#
# with patch('requests.get') as patched_get:
# obj.ticket_get_by_id(1)
# # Ensure patched get was called, called only once and with exactly these params.
# patched_get.assert_called_once_with(mock_url,
# params=mock_payload,
# verify=True)
#
# def test_session_handling(self):
# """ This tests: Test Responses: when calling: get_json_ticket_data_by_ticket_id - Test
# 200 OK;
# Body Error """
# with responses.RequestsMock() as rsps:
# # responses will return this data:
# rsps.add(responses.POST,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST'
# '/Session',
# body={'SessionID': 'fakesessionid'},
# status=200,
# content_type='application/json')
#
# rsps.add(responses.GET,
# 'https://fqdn/otrs/nph-genericinterface.pl/Webservice'
# '/GenericTicketConnectorREST'
# '/Ticket/1',
# body={'Ticket':
# [{'Age': 156717521,
# 'PriorityID': '3',
# 'ServiceID': '',
# 'Type': 'Unclassified',
# 'Responsible': 'root@localhost',
# 'StateID': '2',
# 'ResponsibleID': '1',
# 'ChangeBy': '2',
# 'EscalationTime': '0',
# 'OwnerID': '2',
# 'Changed': '2015-06-08 11:36:17',
# 'RealTillTimeNotUsed': '0',
# 'GroupID': '7',
# 'Owner': 'User',
# 'CustomerID': '',
# 'TypeID': 1,
# 'Created': '2010-08-02 12:00:00',
# 'Priority': '3 normal',
# 'UntilTime': 0,
# 'EscalationUpdateTime': '0',
# 'QueueID': '9',
# 'Queue': 'Operations::OTRS',
# 'State': 'closed',
# 'Title': 'Welcome to OTRS!',
# 'CreateBy': '1',
# 'TicketID': '1',
# 'StateType': 'closed',
# 'UnlockTimeout': '1433763374',
# 'EscalationResponseTime': '0',
# 'EscalationSolutionTime': '0',
# 'LockID': '1',
# 'TicketNumber': '2010080210123456',
# 'ArchiveFlag': 'n',
# 'CreateTimeUnix': '1280750400',
# 'Lock': 'unlock',
# 'SLAID': '',
# 'CustomerUser': 'root@localhost'}]},
# status=200,
# content_type='application/json')
# mock_username = 'correct_username'
# mock_password = 'correct_password'
# with patch('modules.pymisc.send_message_via_mail') as patched_send_message:
# obj = pyotrs.PyOTRS(self.baseurl, self.webservice_name, mock_username,
# mock_password)
""" TODOs
Write tests for
* _get_json_ticket_data with http request failing (e.g. due to wrong fqdn or proxy)
* search_ticket(self, payload)
* _search_json_ticket_data(self, url, payload):
"""
# Main
def main():
unittest.main()
if __name__ == '__main__':
main()
# EOF
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment