Skip to content

Commit 3c5d437

Browse files
author
krgupta
committed
2 bug fixes
1 parent 55dbed3 commit 3c5d437

File tree

5 files changed

+42
-55
lines changed

5 files changed

+42
-55
lines changed

authorizenet/apicontrollersbase.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import abc
77
import logging
88
import xml.dom.minidom
9-
import ConfigParser
10-
from ConfigParser import SafeConfigParser
119
from pip._vendor import requests
1210
from _pyio import __metaclass__
1311

@@ -69,7 +67,7 @@ def beforeexecute(self):
6967
class APIOperationBase(APIOperationBaseInterface):
7068
__metaclass__ = abc.ABCMeta
7169

72-
__initialized = "False"
70+
__initialized = False
7371
__merchantauthentication = "null"
7472

7573
@staticmethod
@@ -83,7 +81,7 @@ def validaterequest(self):
8381
def validate(self):
8482
anetapirequest = self._getrequest()
8583

86-
#self.validateandsetmerchantauthentication()
84+
self.validateandsetmerchantauthentication()
8785
'''
8886
# make sure proper authentication elements are present and no extra elements are present
8987
merchantauthenticationtype = anetapirequest.merchantauthentication()
@@ -197,9 +195,9 @@ def setmerchantauthentication(merchantauthentication):
197195

198196
def validateandsetmerchantauthentication(self):
199197
anetapirequest = apicontractsv1.ANetApiRequest()
200-
if (anetapirequest.getmerchantauthentication() == "null"):
198+
if (anetapirequest.merchantAuthentication == "null"):
201199
if (self.getmerchantauthentication() != "null"):
202-
anetapirequest.setmerchantauthentication(self.getmerchantauthentication())
200+
anetapirequest.merchantAuthentication = self.getmerchantauthentication()
203201
else:
204202
raise ValueError('Merchant Authentication can not be null')
205203
return
@@ -218,20 +216,17 @@ def __init__(self, apiRequest):
218216

219217
APIOperationBase.setmerchantauthentication(__merchantauthentication)
220218

221-
if ( 'False' == APIOperationBase.__classinitialized()):
222-
loggingfilename = utility.helper.getpropertyfile()
223-
logginglevel = utility.helper.getproperty("executionlogginglevel")
224-
225-
#print ("logging level %s" %logginglevel)
226-
219+
if ( False == APIOperationBase.__classinitialized()):
220+
loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename)
221+
logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel)
227222

228223
if ("null" == loggingfilename):
229224
loggingfilename = constants.defaultLogFileName
230225
if ("null" == logginglevel):
231226
logginglevel = constants.defaultLoggingLevel
232227

233228
logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat)
234-
__initialized = "True"
229+
__initialized = True
235230

236231
self.validate()
237232

authorizenet/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,10 @@ class constants(object):
5252

5353
'''default log format'''
5454
defaultlogformat = '%(asctime)s %(message)s'
55+
56+
propertiesloggingfilename = "loggingfilename"
57+
58+
propertiesexecutionlogginglevel = "executionlogginglevel"
5559

60+
5661
'''eof'''

authorizenet/utility.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@
1111
#from authorizenet.constants import constants
1212

1313
class helper():
14-
__parser = SafeConfigParser({"http":"","https":"","ftp":""})
14+
__parser = "null"
1515
__propertyfilename = "null"
1616

17-
__initialized = 'False'
17+
__initialized = False
1818

19-
@staticmethod
20-
def getpropertyfile():
21-
return helper.__propertyfilename
22-
2319
@staticmethod
2420
def getparser():
2521
return helper.__parser
2622

23+
@staticmethod
24+
def getpropertyfile():
25+
return helper.__propertyfilename
26+
2727
@staticmethod
2828
def setpropertyfile(propertyfilename):
29-
if (propertyfilename == 'null' or os.path.isfile(propertyfilename) == 'False'):
30-
raise ValueError('properties '%propertyfilename%' file not found')
31-
32-
helper.__propertyfilename = propertyfilename
29+
if (propertyfilename == 'null' or os.path.isfile(propertyfilename) == False):
30+
helper.__propertyfilename = 'null'
31+
else:
32+
helper.__propertyfilename = propertyfilename
3333
return
3434

3535
@staticmethod
@@ -38,21 +38,28 @@ def __classinitialized():
3838

3939
@staticmethod
4040
def getproperty(propertyname):
41-
42-
if ( 'False' == helper.__classinitialized()):
43-
helper.getparser().read(helper.__propertyfilename)
44-
__initialized = 'True'
45-
4641
stringvalue = "null"
47-
if ("null" != helper.getparser()):
48-
stringvalue = helper.getparser().get("properties", propertyname)
49-
else :
50-
print (" property file does not exist, will read from environment")
51-
stringvalue = os.getenv[propertyname]
42+
if ('null' != helper.getpropertyfile()):
43+
helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""})
44+
if ('null' != helper.getparser()):
45+
try:
46+
if ( False == helper.__classinitialized()):
47+
helper.getparser().read(helper.__propertyfilename)
48+
__initialized = True
49+
except:
50+
print ("helper class not initialized")
51+
if (__initialized == True):
52+
print (" Reading %s from property file %s" % (propertyname, helper.__propertyfilename))
53+
stringvalue = helper.getparser().get("properties", propertyname)
54+
55+
if ( "null" == stringvalue):
56+
print (" Reading %s from environment" %propertyname)
57+
stringvalue = os.getenv('propertyname')
5258

5359
return stringvalue
5460

5561
@staticmethod
5662
def setproperty(propertyname):
57-
helper.getparser().add_option("properties", propertyname)
63+
if ('null' != helper.getparser()):
64+
helper.getparser().add_option("properties", propertyname)
5865
return

tests/anet_python_sdk_properties.ini

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/apitestbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class ApiTestBase(unittest.TestCase):
2020

2121
def setUp(self):
22-
utility.helper.setpropertyfile( 'anet_python_sdk_properties.ini')
22+
utility.helper.setpropertyfile('anet_python_sdk_properties.ini')
2323

2424
self.amount = str(round(random.random()*100, 2))
2525

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy