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

fix tests after type map change

parent 0423e0f5
No related branches found
No related tags found
No related merge requests found
......@@ -451,7 +451,7 @@ class Ticket(object):
"""
result = [x for x in self.list_dynamic_fields if x.name == df_name]
result = [x for x in self.list_dynamic_fields if x.name == "{0}".format(df_name)]
if result:
return result[0]
else:
......
......@@ -101,18 +101,31 @@ class ClientTests(unittest.TestCase):
def test_init_operation_map_override(self):
operation_map_custom = {
'SessionCreate': {'RequestMethod': 'POST', 'Route': '/Session'},
'TicketCreate': {'RequestMethod': 'POST', 'Route': '/Ticket'},
'TicketGet': {'RequestMethod': 'GET', 'Route': '/Ticket/:TicketID'},
'TicketGetList': {'RequestMethod': 'GET', 'Route': '/TicketList'},
'TicketSearch': {'RequestMethod': 'GET', 'Route': '/Ticket'},
'TicketUpdate': {'RequestMethod': 'PATCH', 'Route': '/Ticket/:TicketID'}
'SessionCreate': {'RequestMethod': 'POST',
'Route': '/Session',
'Result': 'SessionID'},
'TicketCreate': {'RequestMethod': 'POST',
'Route': '/Ticket',
'Result': 'TicketID'},
'TicketGet': {'RequestMethod': 'GET',
'Route': '/Ticket/:TicketID',
'Result': 'Ticket'},
'TicketGetList': {'RequestMethod': 'GET',
'Route': '/TicketList',
'Result': 'Ticket'},
'TicketSearch': {'RequestMethod': 'GET',
'Route': '/Ticket',
'Result': 'TicketID'},
'TicketUpdate': {'RequestMethod': 'PATCH',
'Route': '/Ticket/:TicketID',
'Result': 'TicketID'}
}
client = Client(baseurl="http://fqdn/",
webservicename="foo",
operation_map=operation_map_custom)
self.assertIsInstance(client, Client)
"""
def test_init_type_map_override(self):
type_map_custom = {
'SessionCreate': 'SessionID',
......@@ -126,6 +139,7 @@ class ClientTests(unittest.TestCase):
webservicename="foo",
type_map=type_map_custom)
self.assertIsInstance(client, Client)
"""
def test_session_check_is_valid_no_session_id_error(self):
"""Test"""
......@@ -991,7 +1005,7 @@ class ClientTests(unittest.TestCase):
"""Test _send_request no payload"""
obj = Client(baseurl="http://fqdn", webservicename="GenericTicketConnectorREST")
obj.operation = "TicketSearch"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
self.assertRaisesRegex(ArgumentMissingError,
'payload',
......@@ -1001,24 +1015,24 @@ class ClientTests(unittest.TestCase):
"""Test _send_request with invalid http method """
operation_mapping_invalid = {
'SessionCreate':
{'ResultType': 'SessionID', 'RequestMethod': 'FOOBAR', 'Route': '/Session'},
{'Result': 'SessionID', 'RequestMethod': 'FOOBAR', 'Route': '/Session'},
'TicketCreate':
{'ResultType': 'TicketID', 'RequestMethod': 'FOOBAR', 'Route': '/Ticket'},
{'Result': 'TicketID', 'RequestMethod': 'FOOBAR', 'Route': '/Ticket'},
'TicketGet':
{'ResultType': 'Ticket', 'RequestMethod': 'FOOBAR', 'Route': '/Ticket/:TicketID'},
{'Result': 'Ticket', 'RequestMethod': 'FOOBAR', 'Route': '/Ticket/:TicketID'},
'TicketGetList':
{'ResultType': 'Ticket', 'RequestMethod': 'FOOBAR', 'Route': '/TicketList'},
{'Result': 'Ticket', 'RequestMethod': 'FOOBAR', 'Route': '/TicketList'},
'TicketSearch':
{'ResultType': 'TicketID', 'RequestMethod': 'FOOBAR', 'Route': '/Ticket'},
{'Result': 'TicketID', 'RequestMethod': 'FOOBAR', 'Route': '/Ticket'},
'TicketUpdate':
{'ResultType': 'TicketID', 'RequestMethod': 'FOOBAR', 'Route': '/Ticket/:TicketID'}
{'Result': 'TicketID', 'RequestMethod': 'FOOBAR', 'Route': '/Ticket/:TicketID'}
}
obj = Client(baseurl="http://fqdn", webservicename="GenericTicketConnectorREST",
operation_map=operation_mapping_invalid)
obj.operation = "TicketSearch"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
self.assertRaisesRegex(ValueError,
'invalid http_method',
......@@ -1030,7 +1044,7 @@ class ClientTests(unittest.TestCase):
"""Tests _send_request ok"""
obj = Client(baseurl="http://fqdn", webservicename="GenericTicketConnectorREST")
obj.operation = "TicketSearch"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
mock_requests_req.return_value.result = True
mock_requests_req.return_value.status_code = 200
......@@ -1046,7 +1060,7 @@ class ClientTests(unittest.TestCase):
"""Tests _send_request fail http status code not 200"""
obj = Client(baseurl="http://fqdn", webservicename="GenericTicketConnectorREST")
obj.operation = "TicketSearch"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
mock_requests_req.return_value.result = False
mock_requests_req.return_value.status_code = 500
......@@ -1064,7 +1078,7 @@ class ClientTests(unittest.TestCase):
"""Tests _send_request fail"""
obj = Client(baseurl="http://fqdn", webservicename="GenericTicketConnectorREST")
obj.operation = "TicketSearch"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
mock_requests_req.side_effect = Exception("Some Exception")
......@@ -1088,7 +1102,7 @@ class ClientTests(unittest.TestCase):
"""Test _validate_response with an invalid operation"""
obj = Client(baseurl="http://localhost", webservicename="foo")
obj.operation = "DoTheMagicRainDance"
# obj._result_type = obj.type_map[obj.operation]
# obj._result_type = obj.operation_map[obj.operation]["Result"]
mocked_response = mock.Mock(spec=requests.Response)
mocked_response.status_code = 200
......@@ -1103,7 +1117,7 @@ class ClientTests(unittest.TestCase):
"""Test _validate_response with SessionCreate"""
obj = Client(baseurl="http://localhost", webservicename="foo")
obj.operation = "SessionCreate"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
mocked_response = mock.Mock(spec=requests.Response)
mocked_response.status_code = 200
......@@ -1117,7 +1131,7 @@ class ClientTests(unittest.TestCase):
"""Test _validate_response with TicketGet"""
obj = Client(baseurl="http://localhost", webservicename="foo")
obj.operation = "TicketGetList"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
tkt = {u'Ticket': [{u'Age': 24040576,
u'CreateBy': u'1',
......@@ -1142,7 +1156,7 @@ class ClientTests(unittest.TestCase):
"""Test _validate_response with TicketCreate"""
obj = Client(baseurl="http://localhost", webservicename="foo")
obj.operation = "TicketCreate"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
mocked_response = mock.Mock(spec=requests.Response)
mocked_response.status_code = 200
......@@ -1161,7 +1175,7 @@ class ClientTests(unittest.TestCase):
"""Test _validate_response with TicketUpdate"""
obj = Client(baseurl="http://localhost", webservicename="foo")
obj.operation = "TicketCreate"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
mocked_response = mock.Mock(spec=requests.Response)
mocked_response.status_code = 200
......@@ -1176,7 +1190,7 @@ class ClientTests(unittest.TestCase):
"""Test _validate_response with TicketSearch"""
obj = Client(baseurl="http://localhost", webservicename="foo")
obj.operation = "TicketSearch"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
mocked_response = mock.Mock(spec=requests.Response)
mocked_response.status_code = 200
......@@ -1190,7 +1204,7 @@ class ClientTests(unittest.TestCase):
"""Test _validate_response with TicketSearch with empty result"""
obj = Client(baseurl="http://localhost", webservicename="foo")
obj.operation = "TicketSearch"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
mocked_response = mock.Mock(spec=requests.Response)
mocked_response.status_code = 200
......@@ -1204,7 +1218,7 @@ class ClientTests(unittest.TestCase):
"""Test _validate_response with TicketSearch with a nonsence response"""
obj = Client(baseurl="http://localhost", webservicename="foo")
obj.operation = "TicketSearch"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
mocked_response = mock.Mock(spec=requests.Response)
mocked_response.status_code = 200
......@@ -1221,7 +1235,7 @@ class ClientTests(unittest.TestCase):
"""Test _validate_response with TicketGet when an error is received"""
obj = Client(baseurl="http://localhost", webservicename="foo")
obj.operation = "TicketGet"
obj._result_type = obj.type_map[obj.operation]
obj._result_type = obj.operation_map[obj.operation]["Result"]
tkt = {"Error": {"ErrorMessage": "TicketGet: Authorization failing!",
"ErrorCode": "TicketGet.AuthFail"}}
......@@ -1235,6 +1249,14 @@ class ClientTests(unittest.TestCase):
obj._parse_and_validate_response,
mocked_response)
def test_link_add_foo(self):
"""Test link_add foo"""
obj = Client(baseurl="http://localhost", webservicename="foo")
obj.operation = "TicketGet"
obj._result_type = obj.operation_map[obj.operation]["Result"]
self.assertTrue(True)
def main():
unittest.main()
......
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