From 3628e04273e1baf25fd1c322b07d1659e9524aee Mon Sep 17 00:00:00 2001
From: Robert Habermann <mail@rhab.de>
Date: Wed, 13 Apr 2016 22:57:05 +0200
Subject: [PATCH] refactor (cont.)

---
 pyotrs/client.py     |  7 +++----
 tests/test_pyotrs.py | 24 +++++++++++++++---------
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/pyotrs/client.py b/pyotrs/client.py
index a5f5e06..f5a4bff 100644
--- a/pyotrs/client.py
+++ b/pyotrs/client.py
@@ -30,7 +30,6 @@ TicketUpdate                implemented in Class *TicketUpdate(Client)*
 """
 
 import os
-import sys
 import json
 import time
 import datetime
@@ -354,7 +353,7 @@ class Client(object):
         except Exception as err:
             logger.error("Failed to access OTRS. Check Hostname, Proxy, SSL Certificate!"
                          "Error with http communication: {0}".format(err))
-            #raise OTRSHTTPError("get http")
+            # raise OTRSHTTPError("get http")
             raise OTRSHTTPError("Failed to access OTRS. Check Hostname, Proxy, SSL Certificate!"
                                 "Error with http communication: {0}".format(err))
 
@@ -535,7 +534,7 @@ class Client(object):
         except Exception as err:
             logger.error("Failed to access OTRS HTTP. Check Hostname, Proxy, SSL Certificate!"
                          "!Error with http communication: {0}".format(err))
-            #raise OTRSHTTPError("get http")
+            # raise OTRSHTTPError("get http")
             raise OTRSHTTPError("Failed to access OTRS. Check Hostname, Proxy, SSL Certificate!"
                                 "Error with http communication: {0}".format(err))
 
@@ -805,7 +804,7 @@ class Client(object):
         except Exception as err:
             logger.error("Failed to access OTRS. Check Hostname, Proxy, SSL Certificate!"
                          "Error with http communication: {0}".format(err))
-            #raise OTRSHTTPError("get http")
+            # raise OTRSHTTPError("get http")
             raise OTRSHTTPError("Failed to access OTRS. Check Hostname, Proxy, SSL Certificate!"
                                 "Error with http communication: {0}".format(err))
 
diff --git a/tests/test_pyotrs.py b/tests/test_pyotrs.py
index e286d0a..e13680e 100644
--- a/tests/test_pyotrs.py
+++ b/tests/test_pyotrs.py
@@ -91,8 +91,9 @@ class PyOTRSTests(unittest.TestCase):
         }
 
         obj = Client(self.base_url, self.webservice_name, username, password)
+        obj.session_restore_or_set_up_new()
 
-        self.assertRaisesRegexp(OTRSAPIError, 'get api', obj._get_json_ticket_data, url=url,
+        self.assertRaisesRegexp(OTRSAPIError, 'get api', obj._ticket_get_json, url=url,
                                 payload=payload)
 
     """ Test Responses: when calling: get_json_ticket_data_by_ticket_id - Test 200 OK; Body Error
@@ -119,13 +120,14 @@ class PyOTRSTests(unittest.TestCase):
         password = "wrong_password"
 
         obj = Client(self.base_url, self.webservice_name, username, password)
+        obj.session_restore_or_set_up_new()
         obj.ticket_get_by_id(1)
 
         # self.logger.debug(obj.data)
 
         self.assertEqual({"Error": {"ErrorMessage": "TicketGet: Authorization failing!",
-                                    "ErrorCode":    "TicketGet.AuthFail"}}, obj.data.json())
-        self.assertEqual(200, obj.data.status_code)
+                                    "ErrorCode":    "TicketGet.AuthFail"}}, obj.response.json())
+        self.assertEqual(200, obj.response.status_code)
 
     """ Test Responses: update title on valid ticket """
     @responses.activate
@@ -150,10 +152,11 @@ class PyOTRSTests(unittest.TestCase):
         password = "fake_password"
 
         obj = Client(self.base_url, self.webservice_name, 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.data.json())
-        self.assertEqual(200, obj.data.status_code)
+        self.assertEqual({"TicketNumber": "1970010100000010", "TicketID": "10"}, obj.response.json())
+        self.assertEqual(200, obj.response.status_code)
 
     """ Test Responses: update title on invalid ticket (or wrong credentials) """
     @responses.activate
@@ -178,12 +181,13 @@ class PyOTRSTests(unittest.TestCase):
         password = "fake_password"
 
         obj = Client(self.base_url, self.webservice_name, 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.data.json())
-        self.assertEqual(200, obj.data.status_code)
+                         obj.response.json())
+        self.assertEqual(200, obj.response.status_code)
 
     """ 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
@@ -211,15 +215,16 @@ class PyOTRSTests(unittest.TestCase):
 
         ### create object
         obj = Client(self.base_url, self.webservice_name, username, password)
+        obj.session_restore_or_set_up_new()
 
         ### enable Mock
-        obj._get_json_ticket_data = MagicMock()
+        obj._ticket_get_json = MagicMock()
 
         ### call function
         obj.ticket_get_by_id(1)
 
         ### test whether predefined data and call (hooked by MagicMock) match
-        obj._get_json_ticket_data.assert_called_with(url, payload)
+        obj._ticket_get_json.assert_called_with(url, payload)
 
     """ Test Mock: Validate that the right call to requests is made """
     @responses.activate
@@ -243,6 +248,7 @@ class PyOTRSTests(unittest.TestCase):
         mock_password = "wrong_password"
 
         obj = Client(self.base_url, self.webservice_name, mock_username, mock_password)
+        obj.session_restore_or_set_up_new()
 
         with patch('requests.get') as patched_get:
             obj.ticket_get_by_id(1)
-- 
GitLab