forked from AuthorizeNet/sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestssample.py
More file actions
265 lines (244 loc) · 14.2 KB
/
testssample.py
File metadata and controls
265 lines (244 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
'''
Created on Nov 16, 2015
@author: krgupta
'''
from authorizenet import apicontractsv1
from authorizenet.constants import constants
from authorizenet.apicontractsv1 import CTD_ANON
from authorizenet.apicontrollers import *
from decimal import *
import random
import datetime
import unittest
import sys
from tests import apitestbase
from authorizenet import utility
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 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
transactionID = self.testchargeCreditCard()
gettransactiondetailsrequest.transId = transactionID #update valid transaction id
gettransactiondetailscontroller = getTransactionDetailsController(gettransactiondetailsrequest)
gettransactiondetailscontroller.execute()
response = gettransactiondetailscontroller.getresponse()
if hasattr(response, 'messages') == True:
if hasattr(response.messages, 'resultCode') == True:
self.assertEquals('Ok', response.messages.resultCode)
class test_RecurringBillingTest(apitestbase.ApiTestBase):
def testCreateSubscription(self):
createsubscriptionrequest = apicontractsv1.ARBCreateSubscriptionRequest()
createsubscriptionrequest.merchantAuthentication = self.merchantAuthentication
createsubscriptionrequest.refId = 'Sample'
createsubscriptionrequest.subscription = self.subscriptionOne
arbcreatesubscriptioncontroller = ARBCreateSubscriptionController(createsubscriptionrequest)
arbcreatesubscriptioncontroller.execute()
response = arbcreatesubscriptioncontroller.getresponse()
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):
getSubscription = apicontractsv1.ARBGetSubscriptionRequest()
getSubscription.merchantAuthentication = self.merchantAuthentication
subscriptionID = self.testCreateSubscription()
getSubscription.subscriptionId = subscriptionID #update valid subscription id
getSubscriptionController = ARBGetSubscriptionController(getSubscription)
getSubscriptionController.execute()
response = getSubscriptionController.getresponse()
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'
subscriptionID = self.testCreateSubscription()
cancelsubscriptionrequest.subscriptionId = subscriptionID #input valid subscriptionId
cancelsubscriptioncontroller = ARBCancelSubscriptionController (cancelsubscriptionrequest)
cancelsubscriptioncontroller.execute()
response = cancelsubscriptioncontroller.getresponse()
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
createtransactionrequest = apicontractsv1.createTransactionRequest()
createtransactionrequest.merchantAuthentication = self.merchantAuthentication
createtransactionrequest.refId = self.ref_id
createtransactionrequest.transactionRequest = transactionrequesttype
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:
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
transactionrequesttype.payment = self.payment
transactionrequesttype.order = self.order
transactionrequesttype.customer = self.customerData
transactionrequesttype.billTo = self.billTo
createtransactionrequest = apicontractsv1.createTransactionRequest()
createtransactionrequest.merchantAuthentication = self.merchantAuthentication
createtransactionrequest.refId = self.ref_id
createtransactionrequest.transactionRequest = transactionrequesttype
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:
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
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
def testGetSettledBatchList(self):
settledBatchListRequest = apicontractsv1.getSettledBatchListRequest()
settledBatchListRequest.merchantAuthentication = self.merchantAuthentication
settledBatchListController = getSettledBatchListController(settledBatchListRequest)
customEndpoint = constants.PRODUCTION
apicontrollersbase.APIOperationBase.setenvironment(customEndpoint)
settledBatchListController.execute()
response = settledBatchListController.getresponse()
self.assertEquals('Ok', response.messages.resultCode)
def testGetListofSubscriptions(self):
sorting = apicontractsv1.ARBGetSubscriptionListSorting()
sorting.orderBy = apicontractsv1.ARBGetSubscriptionListOrderFieldEnum.id
sorting.orderDescending = "false"
paging = apicontractsv1.Paging()
paging.limit = 1000
paging.offset = 1
GetListofSubscriptionRequest = apicontractsv1.ARBGetSubscriptionListRequest()
GetListofSubscriptionRequest.merchantAuthentication = self.merchantAuthentication
GetListofSubscriptionRequest.refId = "Sample"
GetListofSubscriptionRequest.searchType = apicontractsv1.ARBGetSubscriptionListSearchTypeEnum.subscriptionInactive
GetListofSubscriptionRequest.sorting = sorting
GetListofSubscriptionRequest.paging = paging
arbgetsubscriptionlistcontroller = ARBGetSubscriptionListController(GetListofSubscriptionRequest)
customEndpoint = constants.PRODUCTION
apicontrollersbase.APIOperationBase.setenvironment(customEndpoint)
arbgetsubscriptionlistcontroller.execute()
response = arbgetsubscriptionlistcontroller.getresponse()
self.assertEquals('Ok', response.messages.resultCode)
'''
if __name__ =='__main__':
unittest.main()