Skip to content

updated utility for properties handling #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions authorizenet/apicontrollersbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down Expand Up @@ -69,7 +67,7 @@ def beforeexecute(self):
class APIOperationBase(APIOperationBaseInterface):
__metaclass__ = abc.ABCMeta

__initialized = "False"
__initialized = False
__merchantauthentication = "null"

@staticmethod
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -218,20 +216,17 @@ 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
if ("null" == logginglevel):
logginglevel = constants.defaultLoggingLevel

logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat)
__initialized = "True"
__initialized = True

self.validate()

Expand Down
5 changes: 5 additions & 0 deletions authorizenet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ class constants(object):

'''default log format'''
defaultlogformat = '%(asctime)s %(message)s'

propertiesloggingfilename = "loggingfilename"

propertiesexecutionlogginglevel = "executionlogginglevel"


'''eof'''
61 changes: 29 additions & 32 deletions authorizenet/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,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
Expand All @@ -39,26 +39,23 @@ def __classinitialized():

@staticmethod
def getproperty(propertyname):

if ( 'False' == helper.__classinitialized()):
helper.getparser().read(helper.__propertyfilename)
__initialized = 'True'

stringvalue = "null"
if ("null" != helper.getparser()):
try:
stringvalue = helper.getparser().get("properties", propertyname)
except NoSectionError as nse:
print (" properties section does not exist")
stringvalue = ""

else :
print (" property file does not exist, will read from environment")
stringvalue = os.getenv[propertyname]

return stringvalue

@staticmethod
def setproperty(propertyname):
helper.getparser().add_option("properties", propertyname)
return
temp = 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(temp)
print (" Read propertyvalue %s from environment" %stringvalue)
return stringvalue
20 changes: 0 additions & 20 deletions tests/anet_python_sdk_properties.ini

This file was deleted.

2 changes: 1 addition & 1 deletion tests/apitestbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
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