Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyOTRS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Som Connexió
OTRS
PyOTRS
Commits
c1922c54
Commit
c1922c54
authored
8 years ago
by
Robert Habermann
Browse files
Options
Downloads
Patches
Plain Diff
remove unused test file
parent
0682417d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_pyotrs.py
+0
-317
0 additions, 317 deletions
tests/test_pyotrs.py
with
0 additions
and
317 deletions
tests/test_pyotrs.py
deleted
100644 → 0
+
0
−
317
View file @
0682417d
# -*- 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment