From 3c5d437642db7b5d7bd116e7aad8109ab4a26876 Mon Sep 17 00:00:00 2001 From: krgupta Date: Wed, 11 Nov 2015 13:17:51 -0800 Subject: [PATCH 1/2] 2 bug fixes --- authorizenet/apicontrollersbase.py | 21 +++++------- authorizenet/constants.py | 5 +++ authorizenet/utility.py | 49 ++++++++++++++++------------ tests/anet_python_sdk_properties.ini | 20 ------------ tests/apitestbase.py | 2 +- 5 files changed, 42 insertions(+), 55 deletions(-) delete mode 100644 tests/anet_python_sdk_properties.ini diff --git a/authorizenet/apicontrollersbase.py b/authorizenet/apicontrollersbase.py index 336b86a..d27773a 100644 --- a/authorizenet/apicontrollersbase.py +++ b/authorizenet/apicontrollersbase.py @@ -6,8 +6,6 @@ import abc import logging import xml.dom.minidom -import ConfigParser -from ConfigParser import SafeConfigParser from pip._vendor import requests from _pyio import __metaclass__ @@ -69,7 +67,7 @@ def beforeexecute(self): class APIOperationBase(APIOperationBaseInterface): __metaclass__ = abc.ABCMeta - __initialized = "False" + __initialized = False __merchantauthentication = "null" @staticmethod @@ -83,7 +81,7 @@ def validaterequest(self): def validate(self): anetapirequest = self._getrequest() - #self.validateandsetmerchantauthentication() + self.validateandsetmerchantauthentication() ''' # make sure proper authentication elements are present and no extra elements are present merchantauthenticationtype = anetapirequest.merchantauthentication() @@ -197,9 +195,9 @@ def setmerchantauthentication(merchantauthentication): def validateandsetmerchantauthentication(self): anetapirequest = apicontractsv1.ANetApiRequest() - if (anetapirequest.getmerchantauthentication() == "null"): + if (anetapirequest.merchantAuthentication == "null"): if (self.getmerchantauthentication() != "null"): - anetapirequest.setmerchantauthentication(self.getmerchantauthentication()) + anetapirequest.merchantAuthentication = self.getmerchantauthentication() else: raise ValueError('Merchant Authentication can not be null') return @@ -218,12 +216,9 @@ def __init__(self, apiRequest): APIOperationBase.setmerchantauthentication(__merchantauthentication) - if ( 'False' == APIOperationBase.__classinitialized()): - loggingfilename = utility.helper.getpropertyfile() - logginglevel = utility.helper.getproperty("executionlogginglevel") - - #print ("logging level %s" %logginglevel) - + if ( False == APIOperationBase.__classinitialized()): + loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename) + logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel) if ("null" == loggingfilename): loggingfilename = constants.defaultLogFileName @@ -231,7 +226,7 @@ def __init__(self, apiRequest): logginglevel = constants.defaultLoggingLevel logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat) - __initialized = "True" + __initialized = True self.validate() diff --git a/authorizenet/constants.py b/authorizenet/constants.py index 15b4d21..a4fdb23 100644 --- a/authorizenet/constants.py +++ b/authorizenet/constants.py @@ -52,5 +52,10 @@ class constants(object): '''default log format''' defaultlogformat = '%(asctime)s %(message)s' + + propertiesloggingfilename = "loggingfilename" + + propertiesexecutionlogginglevel = "executionlogginglevel" + '''eof''' diff --git a/authorizenet/utility.py b/authorizenet/utility.py index 9b04fb2..f0fab95 100644 --- a/authorizenet/utility.py +++ b/authorizenet/utility.py @@ -11,25 +11,25 @@ #from authorizenet.constants import constants class helper(): - __parser = SafeConfigParser({"http":"","https":"","ftp":""}) + __parser = "null" __propertyfilename = "null" - __initialized = 'False' + __initialized = False - @staticmethod - def getpropertyfile(): - return helper.__propertyfilename - @staticmethod def getparser(): return helper.__parser + @staticmethod + def getpropertyfile(): + return helper.__propertyfilename + @staticmethod def setpropertyfile(propertyfilename): - if (propertyfilename == 'null' or os.path.isfile(propertyfilename) == 'False'): - raise ValueError('properties '%propertyfilename%' file not found') - - helper.__propertyfilename = propertyfilename + if (propertyfilename == 'null' or os.path.isfile(propertyfilename) == False): + helper.__propertyfilename = 'null' + else: + helper.__propertyfilename = propertyfilename return @staticmethod @@ -38,21 +38,28 @@ def __classinitialized(): @staticmethod def getproperty(propertyname): - - if ( 'False' == helper.__classinitialized()): - helper.getparser().read(helper.__propertyfilename) - __initialized = 'True' - stringvalue = "null" - if ("null" != helper.getparser()): - stringvalue = helper.getparser().get("properties", propertyname) - else : - print (" property file does not exist, will read from environment") - stringvalue = os.getenv[propertyname] + if ('null' != helper.getpropertyfile()): + helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""}) + if ('null' != helper.getparser()): + try: + if ( False == helper.__classinitialized()): + helper.getparser().read(helper.__propertyfilename) + __initialized = True + except: + print ("helper class not initialized") + if (__initialized == True): + print (" Reading %s from property file %s" % (propertyname, helper.__propertyfilename)) + stringvalue = helper.getparser().get("properties", propertyname) + + if ( "null" == stringvalue): + print (" Reading %s from environment" %propertyname) + stringvalue = os.getenv('propertyname') return stringvalue @staticmethod def setproperty(propertyname): - helper.getparser().add_option("properties", propertyname) + if ('null' != helper.getparser()): + helper.getparser().add_option("properties", propertyname) return diff --git a/tests/anet_python_sdk_properties.ini b/tests/anet_python_sdk_properties.ini deleted file mode 100644 index 340289f..0000000 --- a/tests/anet_python_sdk_properties.ini +++ /dev/null @@ -1,20 +0,0 @@ -[properties] - -#sandbox cradentials -api.login.id : 6rF76h2U93AL -transaction.key : 7jh86zEUhy7228FG -md5.hash.key : MD5_HASH_KEY - -#log -logfilename : logFile.log - -#proxy setup -http://internet.visa.com:80 -https://internet.visa.com:443 - -#environments -sandbox : https://apitest.authorize.net/xml/v1/request.api -production : https://api.authorize.net/xml/v1/request.api - -#level -executionlogginglevel : WARNING diff --git a/tests/apitestbase.py b/tests/apitestbase.py index 8b5272f..4ed07f4 100644 --- a/tests/apitestbase.py +++ b/tests/apitestbase.py @@ -19,7 +19,7 @@ class ApiTestBase(unittest.TestCase): def setUp(self): - utility.helper.setpropertyfile( 'anet_python_sdk_properties.ini') + utility.helper.setpropertyfile('anet_python_sdk_properties.ini') self.amount = str(round(random.random()*100, 2)) From 4ae06badc9e12b85c3294afe549ee6fda1df86ae Mon Sep 17 00:00:00 2001 From: krgupta Date: Thu, 12 Nov 2015 15:06:56 -0800 Subject: [PATCH 2/2] error resolved --- authorizenet/utility.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/authorizenet/utility.py b/authorizenet/utility.py index 5623035..4a4fcb1 100644 --- a/authorizenet/utility.py +++ b/authorizenet/utility.py @@ -40,6 +40,7 @@ def __classinitialized(): @staticmethod def getproperty(propertyname): stringvalue = "null" + temp = propertyname if ('null' != helper.getpropertyfile()): helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""}) if ('null' != helper.getparser()): @@ -55,12 +56,6 @@ def getproperty(propertyname): if ( "null" == stringvalue): print (" Reading %s from environment" %propertyname) - stringvalue = os.getenv('propertyname') - - return stringvalue - - @staticmethod - def setproperty(propertyname): - if ('null' != helper.getparser()): - helper.getparser().add_option("properties", propertyname) - return + stringvalue = os.getenv(temp) + print (" Read propertyvalue %s from environment" %stringvalue) + return stringvalue \ No newline at end of file