From 40e655a09003085406d617a5c726b4ebee558ebb Mon Sep 17 00:00:00 2001 From: sapbasu Date: Wed, 30 May 2018 10:20:49 +0530 Subject: [PATCH 1/2] split test dependency and added request package dependency --- .travis.yml | 1 + authorizenet/apicontrollersbase.py | 2 +- setup.py | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f8e8c5..1ee7951 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,7 @@ install: # can't change the pyxb version without changing the version in setup.py # and regenerating the bindings in apicontractsv1.py - pip install lxml + - pip install requests - if [[ "$TEST_SUITE" == "coverage" ]]; then pip install coveralls; fi before_script: diff --git a/authorizenet/apicontrollersbase.py b/authorizenet/apicontrollersbase.py index 41006ee..1859d83 100644 --- a/authorizenet/apicontrollersbase.py +++ b/authorizenet/apicontrollersbase.py @@ -8,7 +8,7 @@ import pyxb import sys import xml.dom.minidom -from pip._vendor import requests +import requests from lxml import objectify from authorizenet.constants import constants diff --git a/setup.py b/setup.py index 9f69f97..2071242 100644 --- a/setup.py +++ b/setup.py @@ -63,12 +63,13 @@ # your project is installed. For an analysis of "install_requires" vs pip's # requirements files see: # https://packaging.python.org/en/latest/requirements.html - install_requires=['pyxb==1.2.5', 'nose', 'mock', 'lxml'], + install_requires=['pyxb==1.2.5', 'lxml', 'requests'], #install_requires=['nose'], #install_requires=['nosetests'], #install_requires=['mock'], #install_requires=['lxml'], + tests_require = ['nose', 'mock'], # List additional groups of dependencies here (e.g. development # dependencies). You can install these using the following syntax, # for example: From 3e49d0d424915e717cd031c51b8d498e38ca6a30 Mon Sep 17 00:00:00 2001 From: sapbasu Date: Wed, 30 May 2018 14:12:45 +0530 Subject: [PATCH 2/2] using separate anetLogger instead of configuring root logger --- authorizenet/apicontrollers.py | 99 +++++++++++++++--------------- authorizenet/apicontrollersbase.py | 38 +++++------- authorizenet/constants.py | 1 + script/ControllerTemplate.pyt | 2 +- script/headertemplate.pyt | 3 +- 5 files changed, 70 insertions(+), 73 deletions(-) diff --git a/authorizenet/apicontrollers.py b/authorizenet/apicontrollers.py index 6f4327a..0184c3e 100644 --- a/authorizenet/apicontrollers.py +++ b/authorizenet/apicontrollers.py @@ -6,7 +6,10 @@ import logging from authorizenet.constants import constants from authorizenet import apicontractsv1 -from authorizenet import apicontrollersbase +from authorizenet import apicontrollersbase + +anetLogger = logging.getLogger(constants.defaultLoggerName) + class ARBCancelSubscriptionController(apicontrollersbase.APIOperationBase): def __init__(self, apirequest): @@ -14,7 +17,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -35,7 +38,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -56,7 +59,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -76,7 +79,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -97,7 +100,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -131,7 +134,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -152,7 +155,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -173,7 +176,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -194,7 +197,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -215,7 +218,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -236,7 +239,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -257,7 +260,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -278,7 +281,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -299,7 +302,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -320,7 +323,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -341,7 +344,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -362,7 +365,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -383,7 +386,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -404,7 +407,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -425,7 +428,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -446,7 +449,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -467,7 +470,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -488,7 +491,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -509,7 +512,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -530,7 +533,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -550,7 +553,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -571,7 +574,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -591,7 +594,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -612,7 +615,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -633,7 +636,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -654,7 +657,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -674,7 +677,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -695,7 +698,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -716,7 +719,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -737,7 +740,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -758,7 +761,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -779,7 +782,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -800,7 +803,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -821,7 +824,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -842,7 +845,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -863,7 +866,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -883,7 +886,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -904,7 +907,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -925,7 +928,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -946,7 +949,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -967,7 +970,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') @@ -988,7 +991,7 @@ def __init__(self, apirequest): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') diff --git a/authorizenet/apicontrollersbase.py b/authorizenet/apicontrollersbase.py index 1859d83..1f8c5e6 100644 --- a/authorizenet/apicontrollersbase.py +++ b/authorizenet/apicontrollersbase.py @@ -19,6 +19,11 @@ from authorizenet.apicontractsv1 import ANetApiRequest from authorizenet.apicontractsv1 import ANetApiResponse ''' + +anetLogger = logging.getLogger(constants.defaultLoggerName) +anetLogger.addHandler(logging.NullHandler()) +logging.getLogger('pyxb.binding.content').addHandler(logging.NullHandler()) + class APIOperationBaseInterface(object): __metaclass__ = abc.ABCMeta @@ -95,7 +100,7 @@ def _getrequest(self): #protected method return self._request def buildrequest(self): - logging.debug('building request..') + anetLogger.debug('building request..') xmlRequest = self._request.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype()) #remove namespaces that toxml() generates @@ -107,7 +112,7 @@ def buildrequest(self): def getprettyxmlrequest(self): xmlRequest = self.buildrequest() requestDom = xml.dom.minidom.parseString(xmlRequest) - logging.debug('Request is: %s' % requestDom.toprettyxml()) + anetLogger.debug('Request is: %s' % requestDom.toprettyxml()) return requestDom @@ -115,7 +120,7 @@ def execute(self): self.endpoint = APIOperationBase.__environment - logging.debug('Executing http post to url: %s', self.endpoint) + anetLogger.debug('Executing http post to url: %s', self.endpoint) self.beforeexecute() @@ -129,8 +134,8 @@ def execute(self): xmlRequest = self.buildrequest() self._httpResponse = requests.post(self.endpoint, data=xmlRequest, headers=constants.headers, proxies=proxyDictionary) except Exception as httpException: - logging.error( 'Error retrieving http response from: %s for request: %s', self.endpoint, self.getprettyxmlrequest()) - logging.error( 'Exception: %s, %s', type(httpException), httpException.args ) + anetLogger.error( 'Error retrieving http response from: %s for request: %s', self.endpoint, self.getprettyxmlrequest()) + anetLogger.error( 'Exception: %s, %s', type(httpException), httpException.args ) if self._httpResponse: @@ -146,7 +151,7 @@ def execute(self): self._mainObject = objectify.fromstring(xmlResponse) except Exception as objectifyexception: - logging.error( 'Create Document Exception: %s, %s', type(objectifyexception), objectifyexception.args ) + anetLogger.error( 'Create Document Exception: %s, %s', type(objectifyexception), objectifyexception.args ) responseString = self._httpResponse # removing encoding attribute as objectify fails if it is present @@ -155,14 +160,14 @@ def execute(self): else: if type(self.getresponseclass()) != type(self._mainObject): if self._response.messages.resultCode == "Error": - logging.debug("Response error") + anetLogger.debug("Response error") domResponse = xml.dom.minidom.parseString(self._httpResponse.encode('utf-8')) - logging.debug('Received response: %s' % domResponse.toprettyxml(encoding='utf-8')) + anetLogger.debug('Received response: %s' % domResponse.toprettyxml(encoding='utf-8')) else: #Need to handle ErrorResponse - logging.debug('Error retrieving response for request: %s' % self._request) + anetLogger.debug('Error retrieving response for request: %s' % self._request) else: - logging.debug("Did not receive http response") + anetLogger.debug("Did not receive http response") return def getresponse(self): @@ -232,19 +237,6 @@ def __init__(self, apiRequest): APIOperationBase.__environment = constants.SANDBOX APIOperationBase.setmerchantauthentication(__merchantauthentication) - - if ( False == APIOperationBase.__classinitialized()): - loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename) - logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel) - - if (None == loggingfilename): - loggingfilename = constants.defaultLogFileName - if (None == logginglevel): - logginglevel = constants.defaultLoggingLevel - - logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat) - __initialized = True - self.validate() return diff --git a/authorizenet/constants.py b/authorizenet/constants.py index 97e5e28..702a557 100644 --- a/authorizenet/constants.py +++ b/authorizenet/constants.py @@ -61,5 +61,6 @@ class constants(object): propertiesexecutionlogginglevel = "executionlogginglevel" + defaultLoggerName = "authorizenet.sdk" '''eof''' diff --git a/script/ControllerTemplate.pyt b/script/ControllerTemplate.pyt index a832732..8ec76ab 100644 --- a/script/ControllerTemplate.pyt +++ b/script/ControllerTemplate.pyt @@ -6,7 +6,7 @@ class APICONTROLLERNAMEController(apicontrollersbase.APIOperationBase): return def validaterequest(self): - logging.debug('performing custom validation..') + anetLogger.debug('performing custom validation..') #validate required fields #if (self._request.xyz == "null"): # raise ValueError('xyz is required') diff --git a/script/headertemplate.pyt b/script/headertemplate.pyt index 848bce6..92d6788 100644 --- a/script/headertemplate.pyt +++ b/script/headertemplate.pyt @@ -6,4 +6,5 @@ Created on Nov 3, 2015 import logging from authorizenet.constants import constants from authorizenet import apicontractsv1 -from authorizenet import apicontrollersbase \ No newline at end of file +from authorizenet import apicontrollersbase +anetLogger = logging.getLogger(constants.defaultLoggerName) \ No newline at end of file