1212NOW = datetime .datetime .now ()
1313
1414EXAMPLE_PRODUCT = {
15- 'name' : 'Example Product' ,
16- 'price' : 1.00
17- }
18-
19- EXAMPLE_OPTION = {
20- 'option_name' : 'Example Option' ,
21- 'option_value_name' : 'Test' ,
22- 'option_value_surcharge' : 1.00
23- }
24-
25- EXAMPLE_COUPON = {
26- 'date_expire' : '2020-12-12' ,
27- 'type' : 'shipping'
15+ 'name' : 'Python Example Product' ,
16+ 'price' : 2.00
2817}
2918
3019EXAMPLE_SALE = {
31- 'sale_id' : 9093717691800
20+ 'sale_id' : 250353589267
3221}
3322
3423EXAMPLE_COMMENT = {
35- 'sale_comment' : "test"
24+ 'sale_comment' : "python2 test"
3625}
3726
3827EXAMPLE_REFUND = {
39- 'comment' : "test " ,
28+ 'comment' : "Python Refund Sale " ,
4029 'category' : 1
4130}
4231
4332EXAMPLE_SHIP = {
44- 'tracking_number' : 123
33+ 'tracking_number' : "test"
4534}
4635
4736EXAMPLE_PASSBACK = {
6150}
6251
6352EXAMPLE_AUTH = {
64- 'merchantOrderId' : '123' ,
65- 'token' : 'NTQyZTQyOTMtNjA0Ni00NzM4LTkyNDItNjVlMmUzZTU2NTNj' ,
66- 'currency' : 'USD' ,
67- 'total' : '1.00' ,
68- 'billingAddr' : {
69- 'name' : 'Testing Tester' ,
70- 'addrLine1' : '123 Test St' ,
71- 'city' : 'Columbus' ,
72- 'state' : 'OH' ,
73- 'zipCode' : '43123' ,
74- 'country' : 'USA' ,
75- 'email' : 'cchristenson@2co.com' ,
76- 'phoneNumber' : '555-555-5555'
53+ "sellerId" : "CREDENTIALS_HERE" ,
54+ "privateKey" : "CREDENTIALS_HERE" ,
55+ "merchantOrderId" : "123" ,
56+ "token" : "CUSTOMER-CLIENT-SIDE-TOKEN" ,
57+ "currency" : "USD" ,
58+ "total" : "2.00" ,
59+ "demo" : True ,
60+ "billingAddr" : {
61+ "name" : "John Doe" ,
62+ "addrLine1" : "123 Test St" ,
63+ "city" : "Columbus" ,
64+ "state" : "Ohio" ,
65+ "zipCode" : "43123" ,
66+ "country" : "USA" ,
67+ "email" : "example@2co.com" ,
68+ "phoneNumber" : "5555555555"
7769 }
7870}
7971
@@ -82,25 +74,40 @@ def setUp(self):
8274 super (TwocheckoutTestCase , self ).setUp ()
8375
8476 twocheckout .Api .credentials ({
85- 'username' : 'testlibraryapi901248204' ,
86- 'password' : 'testlibraryapi901248204PASS' ,
87- 'mode' : 'sandbox'
77+ 'username' : 'CREDENTIALS_HERE' ,
78+ 'password' : 'CREDENTIALS_HERE'
8879 })
8980
9081 twocheckout .Api .auth_credentials ({
91- 'private_key' : 'BE632CB0-BB29-11E3-AFB6-D99C28100996' ,
92- 'seller_id' : '901248204' ,
93- 'mode' : 'sandbox'
82+ 'private_key' : 'CREDENTIALS_HERE' ,
83+ 'seller_id' : 'CREDENTIALS_HERE'
9484 })
9585
86+
87+ class AuthorizationTest (TwocheckoutTestCase ):
88+ def setUp (self ):
89+ super (AuthorizationTest , self ).setUp ()
90+
91+ ## Place order test
92+ def test_1_auth (self ):
93+ params = EXAMPLE_AUTH
94+ try :
95+ result = twocheckout .Charge .authorize (params )
96+
97+ ## use OrderNumber for sale_id for next tests
98+ print ("OrderNumber: " , result .orderNumber )
99+ self .assertEqual (result .responseCode , "APPROVED" )
100+ except TwocheckoutError as error :
101+ self .assertEqual (error .msg , "Unauthorized" )
102+
96103class SaleTest (TwocheckoutTestCase ):
97104 def setUp (self ):
98105 super (SaleTest , self ).setUp ()
99106
100107 def test_1_find_sale (self ):
101108 try :
102109 sale = twocheckout .Sale .find (EXAMPLE_SALE )
103- self .assertEqual (int (sale .sale_id ), 9093717691800 )
110+ self .assertEqual (int (sale .sale_id ), 250353589267 )
104111 except TwocheckoutError as error :
105112 self .assertEqual (error .message , "Unable to find record." )
106113
@@ -115,26 +122,27 @@ def test_3_refund_sale(self):
115122 result = sale .refund (EXAMPLE_REFUND )
116123 self .assertEqual (result .message , "refund added to invoice" )
117124 except TwocheckoutError as error :
118- self .assertEqual (error .message , "Invoice was already refunded ." )
125+ self .assertEqual (error .message , "Amount greater than remaining balance on invoice ." )
119126
127+ ## If you have already run test_3 then test_4 will fail for the same sale_id.
120128 def test_4_refund_invoice (self ):
121129 try :
122130 sale = twocheckout .Sale .find (EXAMPLE_SALE )
123131 invoice = sale .invoices [0 ]
124132 result = invoice .refund (EXAMPLE_REFUND )
125- self .assertEqual (result .message , "refund added to invoice" )
133+ self .assertEqual (result .response_message , "refund added to invoice" )
126134 except TwocheckoutError as error :
127- self .assertEqual (error .message , "Invoice was already refunded ." )
135+ self .assertEqual (error .message , "Amount greater than remaining balance on invoice ." )
128136
129137 def test_5_refund_lineitem (self ):
130138 try :
131139 sale = twocheckout .Sale .find (EXAMPLE_SALE )
132140 invoice = sale .invoices [0 ]
133141 lineitem = invoice .lineitems [0 ]
134142 result = lineitem .refund (EXAMPLE_REFUND )
135- self .assertEqual (result .message , "lineitem refunded" )
143+ self .assertEqual (result .response_message , "lineitem refunded" )
136144 except TwocheckoutError as error :
137- self .assertEqual (error .message , "Lineitem was already refunded ." )
145+ self .assertEqual (error .message , "Lineitem amount greater than remaining balance on invoice ." )
138146
139147 def test_6_stop_sale (self ):
140148 sale = twocheckout .Sale .find (EXAMPLE_SALE )
@@ -147,7 +155,8 @@ def test_7_stop_invoice(self):
147155 result = invoice .stop ()
148156 self .assertEqual (result .response_message , "No active recurring lineitems" )
149157
150- def test_6_stop_sale (self ):
158+ ## If you have already run "test_7_stop_invoice" then "test_8_stop_sale_lineitem" will fail for the same sale_id.
159+ def test_8_stop_sale_lineitem (self ):
151160 sale = twocheckout .Sale .find (EXAMPLE_SALE )
152161 invoice = sale .invoices [0 ]
153162 try :
@@ -156,37 +165,30 @@ def test_6_stop_sale(self):
156165 except TwocheckoutError as error :
157166 self .assertEqual (error .message , "Lineitem is not scheduled to recur." )
158167
159- def test_7_comment (self ):
168+ def test_9_comment (self ):
160169 sale = twocheckout .Sale .find (EXAMPLE_SALE )
161170 result = sale .comment (EXAMPLE_COMMENT )
162171 self .assertEqual (result .response_message , "Created comment successfully." )
163172
164- def test_8_ship (self ):
173+ def test_10_ship (self ):
165174 try :
166175 sale = twocheckout .Sale .find (EXAMPLE_SALE )
167176 result = sale .ship (EXAMPLE_SHIP )
168177 except TwocheckoutError as error :
169178 self .assertEqual (error .message , "Sale already marked shipped." )
170179
171- def test_9_reauth (self ):
172- try :
173- sale = twocheckout .Sale .find (EXAMPLE_SALE )
174- sale .reauth ()
175- except TwocheckoutError as error :
176- self .assertEqual (error .message , "Payment is already pending or deposited and cannot be reauthorized." )
177-
178180class ProductTest (TwocheckoutTestCase ):
179181 def setUp (self ):
180182 super (ProductTest , self ).setUp ()
181183
182184 def test_1_create (self ):
183185 result = twocheckout .Product .create (EXAMPLE_PRODUCT )
184- self .assertEqual (result .response_message , "Product successfully created" )
186+ self .assertEqual (result .response_message , "Product successfully created. " )
185187 EXAMPLE_PRODUCT ['product_id' ] = result .product_id
186188
187189 def test_2_find (self ):
188190 product = twocheckout .Product .find (EXAMPLE_PRODUCT )
189- self .assertEqual (product .name , "Example Product" )
191+ self .assertEqual (product .name , "Python Example Product" )
190192
191193 def test_3_update (self ):
192194 product = twocheckout .Product .find (EXAMPLE_PRODUCT )
@@ -204,75 +206,21 @@ def test_5_list(self):
204206 list = twocheckout .Product .list (params )
205207 self .assertEqual (len (list ), 2 )
206208
207- class OptionTest (TwocheckoutTestCase ):
208- def setUp (self ):
209- super (OptionTest , self ).setUp ()
210-
211- def test_1_create (self ):
212- result = twocheckout .Option .create (EXAMPLE_OPTION )
213- self .assertEqual (result .response_message , "Option created successfully" )
214- EXAMPLE_OPTION ['option_id' ] = result .option_id
215-
216- def test_2_find (self ):
217- option = twocheckout .Option .find (EXAMPLE_OPTION )
218- self .assertEqual (option .option_name , "Example Option" )
219-
220- def test_3_update (self ):
221- option = twocheckout .Option .find (EXAMPLE_OPTION )
222- params = dict ()
223- params ['option_name' ] = "Updated Name"
224- option = option .update (params )
225- self .assertEqual (option .option_name , "Updated Name" )
226-
227- def test_4_delete (self ):
228- option = twocheckout .Option .find (EXAMPLE_OPTION )
229- result = option .delete (EXAMPLE_OPTION )
230- self .assertEqual (result .response_message , "Option deleted successfully" )
231-
232- def test_5_list (self ):
233- params = {'pagesize' : 3 }
234- list = twocheckout .Option .list (params )
235- self .assertEqual (len (list ), 3 )
236-
237- class CouponTest (TwocheckoutTestCase ):
238- def setUp (self ):
239- super (CouponTest , self ).setUp ()
240-
241- def test_1_create (self ):
242- result = twocheckout .Coupon .create (EXAMPLE_COUPON )
243- EXAMPLE_COUPON ['coupon_code' ] = result .coupon_code
244- self .assertEqual (result .response_message , "Coupon successfully created" )
245-
246- def test_2_find (self ):
247- coupon = twocheckout .Coupon .find (EXAMPLE_COUPON )
248- self .assertEqual (coupon .coupon_code , EXAMPLE_COUPON ['coupon_code' ])
249-
250- def test_3_update (self ):
251- coupon = twocheckout .Coupon .find (EXAMPLE_COUPON )
252- EXAMPLE_COUPON ['date_expire' ] = "2020-01-02"
253- coupon = coupon .update (EXAMPLE_COUPON )
254- self .assertEqual (coupon .date_expire , "2020-01-02" )
255-
256- def test_4_delete (self ):
257- coupon = twocheckout .Coupon .find (EXAMPLE_COUPON )
258- result = coupon .delete (EXAMPLE_COUPON )
259- self .assertEqual (result .response_message , "Coupon successfully deleted." )
260-
261209class CompanyTest (TwocheckoutTestCase ):
262210 def setUp (self ):
263211 super (CompanyTest , self ).setUp ()
264212
265213 def test_1_retrieve (self ):
266214 company = twocheckout .Company .retrieve ()
267- self .assertEqual (company .vendor_id , "901248204 " )
215+ self .assertEqual (company .vendor_id , "250111206876 " )
268216
269217class ContactTest (TwocheckoutTestCase ):
270218 def setUp (self ):
271219 super (ContactTest , self ).setUp ()
272220
273221 def test_1_create (self ):
274222 contact = twocheckout .Contact .retrieve ()
275- self .assertEqual (contact .vendor_id , "901248204 " )
223+ self .assertEqual (contact .vendor_id , "250111206876 " )
276224
277225class PaymentTest (TwocheckoutTestCase ):
278226 def setUp (self ):
@@ -304,17 +252,5 @@ def test_1_check(self):
304252 result = twocheckout .Notification .check (params )
305253 self .assertEqual (result .response_code , "SUCCESS" )
306254
307- class AuthorizationTest (TwocheckoutTestCase ):
308- def setUp (self ):
309- super (AuthorizationTest , self ).setUp ()
310-
311- def test_1_auth (self ):
312- params = EXAMPLE_AUTH
313- try :
314- result = twocheckout .Charge .authorize (params )
315- self .assertEqual (result .responseCode , "APPROVED" )
316- except TwocheckoutError as error :
317- self .assertEqual (error .msg , "Unauthorized" )
318-
319255if __name__ == '__main__' :
320256 unittest .main ()
0 commit comments