Skip to content

Commit 91da39a

Browse files
committed
Merge pull request AuthorizeNet#14 from krgupta1/master
updated utility for properties handling
2 parents 6ff6ec5 + 4ae06ba commit 91da39a

File tree

5 files changed

+43
-66
lines changed

5 files changed

+43
-66
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: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@
1212
#from authorizenet.constants import constants
1313

1414
class helper():
15-
__parser = SafeConfigParser({"http":"","https":"","ftp":""})
15+
__parser = "null"
1616
__propertyfilename = "null"
1717

18-
__initialized = 'False'
18+
__initialized = False
1919

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

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

3636
@staticmethod
@@ -39,26 +39,23 @@ def __classinitialized():
3939

4040
@staticmethod
4141
def getproperty(propertyname):
42-
43-
if ( 'False' == helper.__classinitialized()):
44-
helper.getparser().read(helper.__propertyfilename)
45-
__initialized = 'True'
46-
4742
stringvalue = "null"
48-
if ("null" != helper.getparser()):
49-
try:
50-
stringvalue = helper.getparser().get("properties", propertyname)
51-
except NoSectionError as nse:
52-
print (" properties section does not exist")
53-
stringvalue = ""
54-
55-
else :
56-
print (" property file does not exist, will read from environment")
57-
stringvalue = os.getenv[propertyname]
58-
59-
return stringvalue
60-
61-
@staticmethod
62-
def setproperty(propertyname):
63-
helper.getparser().add_option("properties", propertyname)
64-
return
43+
temp = propertyname
44+
if ('null' != helper.getpropertyfile()):
45+
helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""})
46+
if ('null' != helper.getparser()):
47+
try:
48+
if ( False == helper.__classinitialized()):
49+
helper.getparser().read(helper.__propertyfilename)
50+
__initialized = True
51+
except:
52+
print ("helper class not initialized")
53+
if (__initialized == True):
54+
print (" Reading %s from property file %s" % (propertyname, helper.__propertyfilename))
55+
stringvalue = helper.getparser().get("properties", propertyname)
56+
57+
if ( "null" == stringvalue):
58+
print (" Reading %s from environment" %propertyname)
59+
stringvalue = os.getenv(temp)
60+
print (" Read propertyvalue %s from environment" %stringvalue)
61+
return stringvalue

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