From c570208e465606c325dfc7db2cc8062d9021326b Mon Sep 17 00:00:00 2001 From: krgupta Date: Mon, 16 Nov 2015 17:56:34 -0800 Subject: [PATCH] modifications to static function and writing error to stderr --- authorizenet/utility.py | 34 ++++++++++++++++++++-------------- tests/testssample.py | 18 +++++++++++++----- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/authorizenet/utility.py b/authorizenet/utility.py index a18c6a3..a37507a 100644 --- a/authorizenet/utility.py +++ b/authorizenet/utility.py @@ -6,15 +6,13 @@ from ConfigParser import SafeConfigParser from ConfigParser import NoSectionError -'''import ConfigParser''' import os -'''import logging''' -#from authorizenet.constants import constants +import sys +#from __future__ import print_function class helper(): __parser = "null" __propertyfilename = "null" - __initialized = False @staticmethod @@ -40,20 +38,28 @@ def __classinitialized(): @staticmethod def getproperty(propertyname): stringvalue = "null" - temp = propertyname + if ('null' != helper.getpropertyfile()): - helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""}) + if (False == helper.__classinitialized()): + if ('null' == helper.getparser()): + try: + helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""}) + except: + print ("Parser could not be initialized") + if ('null' != helper.getparser()): try: - if ( False == helper.__classinitialized()): - helper.getparser().read(helper.__propertyfilename) - __initialized = True + helper.getparser().read(helper.__propertyfilename) + helper.__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) + print ("Unable to load the property file") + + if (True == helper.__classinitialized()): + try: + stringvalue = helper.getparser().get("properties", propertyname) + except: + sys.stderr.write("%s not found" %propertyname ) if ( "null" == stringvalue): - stringvalue = os.getenv(temp) + stringvalue = os.getenv(propertyname) return stringvalue \ No newline at end of file diff --git a/tests/testssample.py b/tests/testssample.py index 48ba723..112e56a 100644 --- a/tests/testssample.py +++ b/tests/testssample.py @@ -1,5 +1,5 @@ ''' -Created on Jul 13, 2015 +Created on Nov 16, 2015 @author: krgupta ''' @@ -19,9 +19,17 @@ from tests import apitestbase from authorizenet.apicontrollers import * import test +from authorizenet import utility + +class test_ReadProperty(apitestbase.ApiTestBase): + def testPropertyFromFile(self): + login= utility.helper.getproperty("api_login_id") + transactionkey = utility.helper.getproperty("transaction_key") + self.assertIsNotNone(login) + self.assertIsNotNone(transactionkey) class test_TransactionReportingUnitTest(apitestbase.ApiTestBase): - + ''' def testGetTransactionDetails(self): gettransactiondetailsrequest = apicontractsv1.getTransactionDetailsRequest() @@ -31,7 +39,7 @@ def testGetTransactionDetails(self): gettransactiondetailscontroller.execute() response = gettransactiondetailscontroller.getresponse() self.assertEquals('Ok', response.messages.resultCode) - + ''' class test_RecurringBillingTest(apitestbase.ApiTestBase): def testCreateSubscription(self): @@ -45,7 +53,7 @@ def testCreateSubscription(self): response = arbcreatesubscriptioncontroller.getresponse() self.assertIsNotNone(response.subscriptionId) self.assertEquals('Ok', response.messages.resultCode) - + ''' def testcancelSubscription(self): cancelsubscriptionrequest = apicontractsv1.ARBCancelSubscriptionRequest() @@ -56,7 +64,7 @@ def testcancelSubscription(self): cancelsubscriptioncontroller.execute() response = cancelsubscriptioncontroller.getresponse() self.assertEquals('Ok', response.messages.resultCode) - + ''' class paymentTransactionUnitTest(apitestbase.ApiTestBase): def testauthCaputureTransaction(self):