@@ -1260,60 +1260,71 @@ def setUp(self):
12601260 self .paykey = u'fake-paykey'
12611261 self .client .login (username = 'del@icio.us' , password = 'password' )
12621262 self .user = UserProfile .objects .get (username = 'clouserw' )
1263- self .url = reverse ( 'devhub.issue_refund' , args = [ self .addon .slug ] )
1263+ self .url = self .addon .get_dev_url ( 'issue_refund' )
12641264
1265- def makePurchase (self , uuid = '123456' , type = amo .CONTRIB_PURCHASE ):
1265+ def make_purchase (self , uuid = '123456' , type = amo .CONTRIB_PURCHASE ):
12661266 return Contribution .objects .create (uuid = uuid , addon = self .addon ,
12671267 transaction_id = self .transaction_id ,
12681268 user = self .user , paykey = self .paykey ,
12691269 amount = Decimal ('10' ), type = type )
12701270
12711271 def test_request_issue (self ):
1272- c = self .makePurchase ()
1273- r = self .client .get (self .url ,
1274- data = {'transaction_id' : c .transaction_id })
1272+ c = self .make_purchase ()
1273+ r = self .client .get (self .url , {'transaction_id' : c .transaction_id })
12751274 doc = pq (r .content )
1276- eq_ (doc ('#issue-refund button' )[0 ].text .strip (), 'Issue Refund' )
1277- eq_ (doc ('#issue-refund button' )[1 ].text .strip (), 'Decline Refund' )
1275+ eq_ (doc ('#issue-refund button' ).length , 2 )
12781276 eq_ (doc ('#issue-refund input[name=transaction_id]' ).val (),
12791277 self .transaction_id )
12801278
12811279 def test_nonexistent_txn (self ):
1282- r = self .client .get (self .url , data = {'transaction_id' : 'none' })
1280+ r = self .client .get (self .url , {'transaction_id' : 'none' })
12831281 eq_ (r .status_code , 404 )
12841282
12851283 def test_nonexistent_txn_no_really (self ):
12861284 r = self .client .get (self .url )
12871285 eq_ (r .status_code , 404 )
12881286
1289- @mock .patch ('paypal.refund' )
1290- def test_issue (self , refund ):
1291- c = self .makePurchase ()
1292- r = self .client .post (self .url ,
1293- data = {'transaction_id' : c .transaction_id ,
1294- 'issue' : '1' })
1295- eq_ (r .status_code , 302 )
1287+ def _test_issue (self , refund , destination ):
1288+ c = self .make_purchase ()
1289+ r = self .client .post (self .url , {'transaction_id' : c .transaction_id ,
1290+ 'issue' : '1' })
1291+ self .assertRedirects (r , reverse (destination ), 302 )
12961292 refund .assert_called_with (self .transaction_id , self .paykey )
12971293 eq_ (len (mail .outbox ), 1 )
12981294 assert 'approved' in mail .outbox [0 ].subject
12991295
13001296 @mock .patch ('paypal.refund' )
1301- def test_decline (self , refund ):
1302- c = self .makePurchase ()
1303- r = self .client .post (self .url ,
1304- data = {'transaction_id' : c .transaction_id ,
1305- 'decline' : '' })
1306- eq_ (r .status_code , 302 )
1297+ def test_addons_issue (self , refund ):
1298+ self ._test_issue (refund , 'devhub.addons' )
1299+
1300+ @mock .patch ('paypal.refund' )
1301+ def test_apps_issue (self , refund ):
1302+ self .addon .update (type = amo .ADDON_WEBAPP )
1303+ self ._test_issue (refund , 'devhub.apps' )
1304+
1305+ def _test_decline (self , refund , destination ):
1306+ c = self .make_purchase ()
1307+ r = self .client .post (self .url , {'transaction_id' : c .transaction_id ,
1308+ 'decline' : '' })
1309+ self .assertRedirects (r , reverse (destination ), 302 )
13071310 assert not refund .called
13081311 eq_ (len (mail .outbox ), 1 )
13091312 assert 'declined' in mail .outbox [0 ].subject
13101313
1314+ @mock .patch ('paypal.refund' )
1315+ def test_addons_decline (self , refund ):
1316+ self ._test_decline (refund , 'devhub.addons' )
1317+
1318+ @mock .patch ('paypal.refund' )
1319+ def test_apps_decline (self , refund ):
1320+ self .addon .update (type = amo .ADDON_WEBAPP )
1321+ self ._test_decline (refund , 'devhub.apps' )
1322+
13111323 @mock .patch ('paypal.refund' )
13121324 def test_non_refundable_txn (self , refund ):
1313- c = self .makePurchase ('56789' , amo .CONTRIB_VOLUNTARY )
1314- r = self .client .post (self .url ,
1315- data = {'transaction_id' : c .transaction_id ,
1316- 'issue' : '' })
1325+ c = self .make_purchase ('56789' , amo .CONTRIB_VOLUNTARY )
1326+ r = self .client .post (self .url , {'transaction_id' : c .transaction_id ,
1327+ 'issue' : '' })
13171328 eq_ (r .status_code , 404 )
13181329 assert not refund .called
13191330
0 commit comments