"
+ lines = xmlRequest.split( splitString)
+ badXmlElement = "BadElement"
+ badXmlRequest = lines[0] + badXmlElement + splitString + lines[1]
+ logging.debug( "Bad XmlRequest: %s" % badXmlRequest)
+ ##print ("ElementInMidXML Request: %s \n" %badXmlRequest)
+ except Exception as ex:
+ ##print ("ElementInMidXML can not be inserted: %s, %s",type(ex), ex.args)
+ logging.debug( "ElementInMidXML can not be inserted: %s, %s" ,type(ex), ex.args)
+ if (lastElement == True):
+ try:
+ splitStringAtLast = ""
+ lines = xmlRequest.split( splitStringAtLast)
+ badXmlElementAtLast = "BadElementAtLast"
+ badXmlRequest = lines[0] + badXmlElementAtLast + splitStringAtLast + lines[1]
+ logging.debug( "Bad XmlRequest at Last: %s" % badXmlRequest)
+ ##print ("ElementAtLastXML Request: %s \n" %badXmlRequest)
+ except Exception as ex:
+ ##print ("ElementAtLastXML can not be inserted: %s, %s",type(ex), ex.args)
+ logging.debug("ElementAtLastXML can not be inserted: %s, %s",type(ex), ex.args)
+ try:
+ deserializedBadObject = apicontractsv1.CreateFromDocument(badXmlRequest)
+ self.assertIsNotNone(deserializedBadObject, "Null deserializedObject ")
+ badDomXml = deserializedBadObject.toxml(encoding=constants.xml_encoding, element_name='deserializedBadObject')
+ badDomXml = badDomXml.replace(constants.nsNamespace1, '')
+ badDomXml = badDomXml.replace(constants.nsNamespace2, '')
+ logging.debug( "Bad Dom Request: %s " % badDomXml )
+ ##print ("Bad Dom De-serialized: %s \n" %badDomXml)
+ except Exception as ex:
+ logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )
+ ##print ("Exception while de-serializing bad dom: %s, %s",type(ex), ex.args)
+
+class test_CustomerProfile(unittest.TestCase):
+ def testGetCustomerProfile(self):
+ loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename)
+ logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel)
+ logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat)
+
+ merchantAuth = apicontractsv1.merchantAuthenticationType()
+ merchantAuth.name = "unknown"
+ merchantAuth.transactionKey = "anon"
+
+ getCustomerProfileRequest = apicontractsv1.getCustomerProfileRequest()
+ getCustomerProfileRequest.merchantAuthentication = merchantAuth
+ getCustomerProfileRequest.customerProfileId = '36152115'
+ getCustomerProfileRequest.abc = 'aaaaaaaa' #extra property not in getCustomerProfileRequest object
+
+ logging.debug( "Request: %s " % datetime.datetime.now())
+ logging.debug( " : %s " % getCustomerProfileRequest )
+
+ try:
+ '''serialzing object to XML '''
+ xmlRequest = getCustomerProfileRequest.toxml(encoding=constants.xml_encoding, element_name='getCustomerProfileRequest')
+ xmlRequest = xmlRequest.replace(constants.nsNamespace1, b'')
+ xmlRequest = xmlRequest.replace(constants.nsNamespace2, b'')
+ logging.debug( "Xml Request: %s" % xmlRequest)
+ #print( "Xml Request: %s" % xmlRequest)
+ except Exception as ex:
+ logging.debug( "Xml Exception: %s" % ex)
+
+ try:
+ '''deserialize XML to object '''
+ deserializedObject = None
+ deserializedObject = apicontractsv1.CreateFromDocument(xmlRequest)
+ self.assertIsNotNone(deserializedObject, "Null deserializedObject ")
+
+ if type(getCustomerProfileRequest) == type(deserializedObject):
+ #print ("objects are equal")
+ logging.debug( "createtransactionrequest object is equal to deserializedObject")
+ else:
+ #print ("some error: objects are NOT equal" )
+ logging.debug( "createtransactionrequest object is NOT equal to deserializedObject")
+
+ deseriaziedObjectXmlRequest = deserializedObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject')
+ deseriaziedObjectXmlRequest = deseriaziedObjectXmlRequest.replace(constants.nsNamespace1, '')
+ deseriaziedObjectXmlRequest = deseriaziedObjectXmlRequest.replace(constants.nsNamespace2, '')
+ logging.debug( "Good Dom Request: %s " % deseriaziedObjectXmlRequest )
+ #print( "Good Dom Request: %s " % deseriaziedObjectXmlRequest )
+ #print("de-serialized successfully. GOOD CASE COMPLETE \n ")
+ except Exception as ex:
+
+ logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )
+
+ self.assertEqual(type(getCustomerProfileRequest), type(deserializedObject), "deseriaziedObject does not match original object")
+
+ try:
+ #print("starting with element in mid")
+ newxml = 'unknownanon11Jan36152115'
+
+ #print ("newxml: %s" %newxml)
+ DEserializedNEWObject = apicontractsv1.CreateFromDocument(newxml)
+ self.assertIsNotNone(DEserializedNEWObject, "Null deserializedObject ")
+
+
+ DEseriaziedNEWObjectXmlRequest = DEserializedNEWObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject')
+ DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace1, '')
+ DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace2, '')
+ logging.debug( "Good Dom Request: %s " % DEseriaziedNEWObjectXmlRequest )
+ #print( " DEseriaziedNEWObjectXmlRequest Request: %s " % DEseriaziedNEWObjectXmlRequest )
+ #print("de-serialized successfully")
+ #print("FINISHED element in mid \n ")
+ except Exception as ex:
+ #print("DEseriaziedNEWObjectXmlRequest is NOT DESerialized")
+ logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )
+
+
+ try:
+ #print("starting with element at last")
+ newxmlATLAst = 'unknownanon3615211511Jan'
+ #print ("newxmlATLAst: %s" %newxmlATLAst)
+ DEserializedNEWObject = apicontractsv1.CreateFromDocument(newxmlATLAst)
+ self.assertIsNotNone(DEserializedNEWObject, "Null deserializedObject ")
+ DEseriaziedNEWObjectXmlRequest = DEserializedNEWObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject')
+ DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace1, '')
+ DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace2, '')
+ logging.debug( "Good Dom Request: %s " % DEseriaziedNEWObjectXmlRequest )
+ #print( " DEseriaziedNEWATLASTObjectXmlRequest Request: %s " % DEseriaziedNEWObjectXmlRequest )
+ #print("de-serialized successfully")
+ #print("Finished element at last \n " )
+ except Exception as ex:
+ #print("DEseriaziedNEWATLASTObjectXmlRequest is NOT DESerialized")
+ logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )
+
+if __name__ =='__main__':
+ unittest.main()
diff --git a/tests/testssample.py b/tests/testssample.py
index 65c1916..1e04498 100644
--- a/tests/testssample.py
+++ b/tests/testssample.py
@@ -4,51 +4,68 @@
@author: krgupta
'''
from authorizenet import apicontractsv1
-from authorizenet import constants
-from decimal import *
+from authorizenet.constants import constants
from authorizenet.apicontractsv1 import CTD_ANON
-#from controller.CreateTransactionController import CreateTransactionController
from authorizenet.apicontrollers import *
-from ConfigParser import SafeConfigParser
+from decimal import *
+import random
import datetime
-from tests import apitestbase
-#from tests import *
-import os
import unittest
-from authorizenet import apicontractsv1
-#from controller.ARBCancelSubscriptionController import ARBCancelSubscriptionController
+import sys
from tests import apitestbase
-from authorizenet.apicontrollers import *
-import test
from authorizenet import utility
-from authorizenet.apicontrollersbase import APIOperationBase
class test_ReadProperty(apitestbase.ApiTestBase):
def testPropertyFromFile(self):
login= utility.helper.getproperty("api.login.id")
+ if (login) == None:
+ login= utility.helper.getproperty("api_login_id")
transactionkey = utility.helper.getproperty("transaction.key")
+ if (transactionkey) == None:
+ transactionkey= utility.helper.getproperty("transaction_key")
self.assertIsNotNone(login)
self.assertIsNotNone(transactionkey)
-
-
+
class test_TransactionReportingUnitTest(apitestbase.ApiTestBase):
- def testGetTransactionDetails(self):
-
+ def testchargeCreditCard(self):
+ creditCard = apicontractsv1.creditCardType()
+ creditCard.cardNumber = "4111111111111111"
+ creditCard.expirationDate = "2020-12"
+ payment = apicontractsv1.paymentType()
+ payment.creditCard = creditCard
+ transactionrequest = apicontractsv1.transactionRequestType()
+ transactionrequest.transactionType = "authCaptureTransaction"
+ transactionrequest.amount = Decimal(str(round(random.random()*100, 2)))
+ transactionrequest.payment = payment
+ createtransactionrequest = apicontractsv1.createTransactionRequest()
+ createtransactionrequest.merchantAuthentication = self.merchantAuthentication
+ createtransactionrequest.refId = "MerchantID-0001"
+ createtransactionrequest.transactionRequest = transactionrequest
+ createtransactioncontroller = createTransactionController(createtransactionrequest)
+ createtransactioncontroller.execute()
+ response = createtransactioncontroller.getresponse()
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+ if hasattr(response, 'transactionResponse') == True:
+ if hasattr(response.transactionResponse, 'transId') == True:
+ createdTransactionId = response.transactionResponse.transId
+ return str(createdTransactionId)
+
+ def testgetTransactionDetails(self):
gettransactiondetailsrequest = apicontractsv1.getTransactionDetailsRequest()
gettransactiondetailsrequest.merchantAuthentication = self.merchantAuthentication
- gettransactiondetailsrequest.transId ='2252271173' #update valid transaction id
+ transactionID = self.testchargeCreditCard()
+ gettransactiondetailsrequest.transId = transactionID #update valid transaction id
gettransactiondetailscontroller = getTransactionDetailsController(gettransactiondetailsrequest)
gettransactiondetailscontroller.execute()
response = gettransactiondetailscontroller.getresponse()
- self.assertEquals('Ok', response.messages.resultCode)
-
-
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+
class test_RecurringBillingTest(apitestbase.ApiTestBase):
-
- createdSubscriptionId = None
-
def testCreateSubscription(self):
-
createsubscriptionrequest = apicontractsv1.ARBCreateSubscriptionRequest()
createsubscriptionrequest.merchantAuthentication = self.merchantAuthentication
createsubscriptionrequest.refId = 'Sample'
@@ -56,47 +73,47 @@ def testCreateSubscription(self):
arbcreatesubscriptioncontroller = ARBCreateSubscriptionController(createsubscriptionrequest)
arbcreatesubscriptioncontroller.execute()
response = arbcreatesubscriptioncontroller.getresponse()
- self.assertIsNotNone(response.subscriptionId)
- self.assertEquals('Ok', response.messages.resultCode)
- self.__class__.createdSubscriptionId = response.subscriptionId
-
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+ if hasattr(response, 'subscriptionId') == True:
+ createdSubscriptionId = response.subscriptionId
+ return str(createdSubscriptionId)
- def testgetsubscription(self):
-
+ def testGetSubscription(self):
getSubscription = apicontractsv1.ARBGetSubscriptionRequest()
getSubscription.merchantAuthentication = self.merchantAuthentication
- getSubscription.subscriptionId = self.__class__.createdSubscriptionId #update valid subscription id
+ subscriptionID = self.testCreateSubscription()
+ getSubscription.subscriptionId = subscriptionID #update valid subscription id
getSubscriptionController = ARBGetSubscriptionController(getSubscription)
getSubscriptionController.execute()
response = getSubscriptionController.getresponse()
- self.assertIsNotNone(response.subscription.name)
- self.assertEquals('Ok', response.messages.resultCode)
-
-
- def testcancelSubscription(self):
-
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+
+ def testCancelSubscription(self):
cancelsubscriptionrequest = apicontractsv1.ARBCancelSubscriptionRequest()
cancelsubscriptionrequest.merchantAuthentication = self.merchantAuthentication
cancelsubscriptionrequest.refId = 'Sample'
- cancelsubscriptionrequest.subscriptionId = self.__class__.createdSubscriptionId #input valid subscriptionId
+ subscriptionID = self.testCreateSubscription()
+ cancelsubscriptionrequest.subscriptionId = subscriptionID #input valid subscriptionId
cancelsubscriptioncontroller = ARBCancelSubscriptionController (cancelsubscriptionrequest)
cancelsubscriptioncontroller.execute()
response = cancelsubscriptioncontroller.getresponse()
- self.assertEquals('Ok', response.messages.resultCode)
-
-
-class paymentTransactionUnitTest(apitestbase.ApiTestBase):
-
- def testauthCaptureTransaction(self):
-
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+
+class test_paymentTransactionUnitTest(apitestbase.ApiTestBase):
+ def testAuthCaptureTransaction(self):
transactionrequesttype = apicontractsv1.transactionRequestType()
transactionrequesttype.transactionType = "authCaptureTransaction"
transactionrequesttype.amount = self.amount
transactionrequesttype.payment = self.payment
transactionrequesttype.order = self.order
transactionrequesttype.customer = self.customerData
- transactionrequesttype.billTo = self.billTo
-
+ transactionrequesttype.billTo = self.billTo
createtransactionrequest = apicontractsv1.createTransactionRequest()
createtransactionrequest.merchantAuthentication = self.merchantAuthentication
createtransactionrequest.refId = self.ref_id
@@ -104,13 +121,15 @@ def testauthCaptureTransaction(self):
createtransactioncontroller = createTransactionController(createtransactionrequest)
createtransactioncontroller.execute()
response = createtransactioncontroller.getresponse()
- self.assertIsNotNone(response)
- self.assertIsNotNone(response.transactionResponse)
- self.assertIsNotNone(response.transactionResponse.transId)
- self.assertIsNot("0", response.transactionResponse.transId)
-
- def testauthOnlyContinueTransaction(self):
-
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+ if hasattr(response, 'transactionResponse') == True:
+ self.assertIsNotNone(response.transactionResponse)
+ if hasattr(response.transactionResponse, 'transId') == True:
+ self.assertIsNotNone(response.transactionResponse.transId)
+
+ def testAuthOnlyContinueTransaction(self):
transactionrequesttype = apicontractsv1.transactionRequestType()
transactionrequesttype.transactionType = "authCaptureTransaction"
transactionrequesttype.amount = self.amount
@@ -118,7 +137,6 @@ def testauthOnlyContinueTransaction(self):
transactionrequesttype.order = self.order
transactionrequesttype.customer = self.customerData
transactionrequesttype.billTo = self.billTo
-
createtransactionrequest = apicontractsv1.createTransactionRequest()
createtransactionrequest.merchantAuthentication = self.merchantAuthentication
createtransactionrequest.refId = self.ref_id
@@ -126,12 +144,92 @@ def testauthOnlyContinueTransaction(self):
createtransactioncontroller = createTransactionController(createtransactionrequest)
createtransactioncontroller.execute()
response = createtransactioncontroller.getresponse()
- self.assertIsNotNone(response.transactionResponse)
- self.assertIsNotNone(response.transactionResponse.transId)
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+ if hasattr(response, 'transactionResponse') == True:
+ self.assertIsNotNone(response.transactionResponse)
+ if hasattr(response.transactionResponse, 'transId') == True:
+ self.assertIsNotNone(response.transactionResponse.transId)
+
+class test_CustomerProfile(apitestbase.ApiTestBase):
+ def testCreateCustomerProfile(self):
+ createdCustomerProfileID = None
+ createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
+ createCustomerProfile.merchantAuthentication = self.merchantAuthentication
+ randomInt = random.randint(0, 10000)
+ createCustomerProfile.profile = apicontractsv1.customerProfileType()
+ createCustomerProfile.profile.merchantCustomerId = 'jdoe%s' % randomInt
+ createCustomerProfile.profile.description = 'John Doe%s' % randomInt
+ createCustomerProfile.profile.email = 'jdoe%s@mail.com' % randomInt
+ controller = createCustomerProfileController(createCustomerProfile)
+ controller.execute()
+ response = controller.getresponse()
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+ if hasattr(response, 'customerProfileId') == True:
+ createdCustomerProfileID = response.customerProfileId
+ return str(createdCustomerProfileID)
+
+ def testGetCustomerProfile(self):
+ getCustomerProfile = apicontractsv1.getCustomerProfileRequest()
+ getCustomerProfile.merchantAuthentication = self.merchantAuthentication
+
+ CustomerProfileID = self.testCreateCustomerProfile()
+ getCustomerProfile.customerProfileId = CustomerProfileID
+ controller = getCustomerProfileController(getCustomerProfile)
+ controller.execute()
+ response = controller.getresponse()
+ self.assertEquals('Ok', response.messages.resultCode)
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+
+ def testCreateAndGetCustomerShippingAddress(self):
+ officeAddress = apicontractsv1.customerAddressType();
+ officeAddress.firstName = "John"
+ officeAddress.lastName = "Doe"
+ officeAddress.address = "123 Main St."
+ officeAddress.city = "Bellevue"
+ officeAddress.state = "WA"
+ officeAddress.zip = "98004"
+ officeAddress.country = "USA"
+ officeAddress.phoneNumber = "000-000-0000"
+ shippingAddressRequest = apicontractsv1.createCustomerShippingAddressRequest()
+ shippingAddressRequest.address = officeAddress
+ CustomerProfileID = self.testCreateCustomerProfile()
+ shippingAddressRequest.customerProfileId = CustomerProfileID
+ shippingAddressRequest.merchantAuthentication = self.merchantAuthentication
+ controller = createCustomerShippingAddressController(shippingAddressRequest)
+ controller.execute()
+ response = controller.getresponse()
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+ if hasattr(response, 'customerAddressId') == True:
+ createdShippingAddressId = str(response.customerAddressId)
+ #return str(createdShippingAddressId)
+
+ #def testGetCustomerShippingAddress(self):
+ getShippingAddress = apicontractsv1.getCustomerShippingAddressRequest()
+ getShippingAddress.merchantAuthentication = self.merchantAuthentication
+
+
+ getShippingAddress.customerProfileId = CustomerProfileID
+ getShippingAddress.customerAddressId = createdShippingAddressId
+
+ getShippingAddressController = getCustomerShippingAddressController(getShippingAddress)
+ getShippingAddressController.execute()
+ response = getShippingAddressController.getresponse()
+ if hasattr(response, 'messages') == True:
+ if hasattr(response.messages, 'resultCode') == True:
+ self.assertEquals('Ok', response.messages.resultCode)
+
'''
class test_ProductionURL(apitestbase.ApiTestBase):
- '' '' ''Tests will run only with production credentials
- '' '' ''
+ #Tests will run only with production credentials
+
def testGetSettledBatchList(self):
settledBatchListRequest = apicontractsv1.getSettledBatchListRequest()
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