From f0538293deac22d42254775dcbf14cbcc08a643f Mon Sep 17 00:00:00 2001 From: Rishi Gupta Date: Wed, 28 Nov 2018 00:07:21 -0800 Subject: [PATCH] billing: Update test_replace_payment_source to use mock_stripe. --- ...lace_payment_source:Customer.create.1.json | Bin 0 -> 1583 bytes ...ce_payment_source:Customer.retrieve.1.json | Bin 0 -> 4882 bytes ...ce_payment_source:Customer.retrieve.2.json | Bin 0 -> 4894 bytes ...ce_payment_source:Customer.retrieve.3.json | Bin 0 -> 4894 bytes ...ce_payment_source:Customer.retrieve.4.json | Bin 0 -> 4894 bytes ...eplace_payment_source:Customer.save.1.json | Bin 0 -> 4253 bytes ...eplace_payment_source:Customer.save.2.json | Bin 0 -> 1435 bytes ..._payment_source:Subscription.create.1.json | Bin 0 -> 2160 bytes ...replace_payment_source:Token.create.1.json | Bin 0 -> 826 bytes ...replace_payment_source:Token.create.2.json | Bin 0 -> 832 bytes ...replace_payment_source:Token.create.3.json | Bin 0 -> 826 bytes corporate/tests/test_stripe.py | 61 +++++++++++------- stubs/stripe/__init__.pyi | 1 + 13 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Customer.create.1.json create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Customer.retrieve.1.json create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Customer.retrieve.2.json create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Customer.retrieve.3.json create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Customer.retrieve.4.json create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Customer.save.1.json create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Customer.save.2.json create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Subscription.create.1.json create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Token.create.1.json create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Token.create.2.json create mode 100644 corporate/tests/stripe_fixtures/replace_payment_source:Token.create.3.json diff --git a/corporate/tests/stripe_fixtures/replace_payment_source:Customer.create.1.json b/corporate/tests/stripe_fixtures/replace_payment_source:Customer.create.1.json new file mode 100644 index 0000000000000000000000000000000000000000..38df17258fe9fa0ba8b99af1c8ade19849fcbaea GIT binary patch literal 1583 zcmb_cOK;RL5We?UL^**}(R~#OPE;xfBwnH_hazOnIumxNV+Y$=?Y8QFXU1`Mv!yG9 zL@r6@`OPx9-zTeU zOWg9}Dstz;Q?}eNoJzcFTcI!F3X6bndel_u73y1YXdxVpIAepM$VcFUKsm0yqgH~? z<#`GO>yJZNda!9EzEXg(cN(nB$kl;jXc6Z;GDjJ|UhCtDtF48Gv@#Il;?Lr6)2hbV zxMI~@h9t)n`4&N@Xf~OTH8l?k`qoogrG9YtYd6fHgemLJR{dDXhF28F_2muu>*{7e z1O9R`Tg=9B#(R;*JUejN(#-Or0vR&j&w5slHh}?*!$o(CmhM1Kg5uaKCvB67$>cnw z_xGMF-u}S+`GZyE%J=aNg`w;+x(G%MrzBlCw(WenBWLUB*|3&Dz8+nUvtc7Sf4|P5 sTkfvc6N~yEAg1g5FAxt9?SMwuD6+N7M5bFb$kZCWT#H2b!1Tk(Z$(hFFaQ7m literal 0 HcmV?d00001 diff --git a/corporate/tests/stripe_fixtures/replace_payment_source:Customer.retrieve.1.json b/corporate/tests/stripe_fixtures/replace_payment_source:Customer.retrieve.1.json new file mode 100644 index 0000000000000000000000000000000000000000..2bd90e7f59114f56ed195178c87cb5d5adcb321d GIT binary patch literal 4882 zcmc&&OK%%D5Wf3Y2t2hw5KETaSOtnUsCy{THbva@kfInwWABa3#qqS(xq68E*L_5Dm9p$ z-8ryshqzpqYJrA7m69puc*Qjub zKSQG+OPkynQDPj~pW2G{76m=L_^vx_tg8xT5G)(ZfBW$9*Z05t{Q0Nb`Fy_UPcOPC5e!7RWezMio>Z-k8C?_)E1ZaMK37*2UFd^)HCa^G!X~EUz zA0^38G}xZH>OqzINjP1V9Q5rf^a(Q!i6)&aQ&37@8by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 0 HcmV?d00001 diff --git a/corporate/tests/stripe_fixtures/replace_payment_source:Customer.retrieve.3.json b/corporate/tests/stripe_fixtures/replace_payment_source:Customer.retrieve.3.json new file mode 100644 index 0000000000000000000000000000000000000000..8529bf3332e230e738f5ff30a8565a661f1e8e6a GIT binary patch literal 4894 zcmc&&OK%%D5Wf3Y2t2hw5KETaSOtnUhA?miW*@_pu5|aHmnZChup(VF6hyTy67xVdY@x%4Z z30kdXCH5d;t;rc3=5o#3!e*v!H7R)p9jHCewKOIZ%F=~TT&T4YbSW023z`sLDg|aI z_ZF<1A+AuBoT1?_RW9|!Zso*C{w4{_#8!$21UK9yHC=(QYKsD25IJMebXxSJ8dNyP zpP^BZrA@9huP~16BR5v+4_v#TVUVMD-v@=FHMTCL#w+kS`{VBO$M?Vg_Vw4>>2x~l zP&<(}m+vcHDv=dnZP9;*d~C9^uIv_$=l<1rwwD~OT}|iVbgin5)Qwh^MK^jbOs7}D ziFI4$fJ6w?ORj7XD0;Afr}o{47xe5~DQAy{NscKg%A+tuy zwR%J?6n39-R;ZmU>l{OHa5avTt72%|qRgD7u2|fmu~bv!6zhTzMK2T{y~S)*)41e@ zCSk6<4Y=U@+vn&nvOV#qy>3c(ejgHbL8AM6*wYMf3{CdP5vw%h>Q>R!Xb@j-u~Oh=fuw!Fv!q0poSY^#Y) zE_bubFcl1b>XYj1GW2EF)TUi^9Clv2Hcg>~Bg?e}5|S{-i5Elj>EQfu@?ovDzUARfcpCcX@xSz<)g^BMa!zrGf6YEW4azp<^Tju z1J}k@mT;FAmw|!V^}EG#KK08@8VMAj(OlZ`vwJb;dy~PQqlzqV`wIrzg|Rc(p$5-O z3>@z-#A+lYu9Kh|1{D*h3HGh>P$ORDfY{xsBYpQ7|4l84SFZXakoQ52yWqfVq+PxA z&^K{$XXt(O8V_z@neC?3!546u3k!o3WLCE{?qey+HybTCumNVR;hW<$1vuj+jxA7h z0~^io(V)mTN@idWb&CsBHsrrsl7c4u-HYUWc{86a-+2<~!xGDP3;<0o+!%oDww^zJ z*sY%KZkBiE^HG!#T){@V4}E~%#fX8yUFb&27s-T=>>VE#6w_aUR5o4mGI_J z29)CjqS1BUx_uBoQWO@;#l5tD-ZqaZomNSW9nf#M;65WUP&w^hV;ETS&AQg*Yh`1# z0;2aMhmi%8Ak(E6Hd^#}=c~VF`j6 zrjVC6ZSu1Xji4Z|*MaXVb=M!sw)FsyLB}Q}pl}F+|xqq6GFI$iVe^q8(2Y z0JE>QK0sb?diY}s%$pPK9@lib#o5VC1;5F(NH?KS58S{ke~ebX>Dy?adFS0e)@MI2 r3RY3*x#R!agnNr`w-4j{RJE?7?9!X@EZf1x34fHL<<|o)UM~IxFi`|d literal 0 HcmV?d00001 diff --git a/corporate/tests/stripe_fixtures/replace_payment_source:Customer.retrieve.4.json b/corporate/tests/stripe_fixtures/replace_payment_source:Customer.retrieve.4.json new file mode 100644 index 0000000000000000000000000000000000000000..8529bf3332e230e738f5ff30a8565a661f1e8e6a GIT binary patch literal 4894 zcmc&&OK%%D5Wf3Y2t2hw5KETaSOtnUhA?miW*@_pu5|aHmnZChup(VF6hyTy67xVdY@x%4Z z30kdXCH5d;t;rc3=5o#3!e*v!H7R)p9jHCewKOIZ%F=~TT&T4YbSW023z`sLDg|aI z_ZF<1A+AuBoT1?_RW9|!Zso*C{w4{_#8!$21UK9yHC=(QYKsD25IJMebXxSJ8dNyP zpP^BZrA@9huP~16BR5v+4_v#TVUVMD-v@=FHMTCL#w+kS`{VBO$M?Vg_Vw4>>2x~l zP&<(}m+vcHDv=dnZP9;*d~C9^uIv_$=l<1rwwD~OT}|iVbgin5)Qwh^MK^jbOs7}D ziFI4$fJ6w?ORj7XD0;Afr}o{47xe5~DQAy{NscKg%A+tuy zwR%J?6n39-R;ZmU>l{OHa5avTt72%|qRgD7u2|fmu~bv!6zhTzMK2T{y~S)*)41e@ zCSk6<4Y=U@+vn&nvOV#qy>3c(ejgHbL8AM6*wYMf3{CdP5vw%h>Q>R!Xb@j-u~Oh=fuw!Fv!q0poSY^#Y) zE_bubFcl1b>XYj1GW2EF)TUi^9Clv2Hcg>~Bg?e}5|S{-i5Elj>EQfu@?ovDzUARfcpCcX@xSz<)g^BMa!zrGf6YEW4azp<^Tju z1J}k@mT;FAmw|!V^}EG#KK08@8VMAj(OlZ`vwJb;dy~PQqlzqV`wIrzg|Rc(p$5-O z3>@z-#A+lYu9Kh|1{D*h3HGh>P$ORDfY{xsBYpQ7|4l84SFZXakoQ52yWqfVq+PxA z&^K{$XXt(O8V_z@neC?3!546u3k!o3WLCE{?qey+HybTCumNVR;hW<$1vuj+jxA7h z0~^io(V)mTN@idWb&CsBHsrrsl7c4u-HYUWc{86a-+2<~!xGDP3;<0o+!%oDww^zJ z*sY%KZkBiE^HG!#T){@V4}E~%#fX8yUFb&27s-T=>>VE#6w_aUR5o4mGI_J z29)CjqS1BUx_uBoQWO@;#l5tD-ZqaZomNSW9nf#M;65WUP&w^hV;ETS&AQg*Yh`1# z0;2aMhmi%8Ak(E6Hd^#}=c~VF`j6 zrjVC6ZSu1Xji4Z|*MaXVb=M!sw)FsyLB}Q}pl}F+|xqq6GFI$iVe^q8(2Y z0JE>QK0sb?diY}s%$pPK9@lib#o5VC1;5F(NH?KS58S{ke~ebX>Dy?adFS0e)@MI2 r3RY3*x#R!agnNr`w-4j{RJE?7?9!X@EZf1x34fHL<<|o)UM~IxFi`|d literal 0 HcmV?d00001 diff --git a/corporate/tests/stripe_fixtures/replace_payment_source:Customer.save.1.json b/corporate/tests/stripe_fixtures/replace_payment_source:Customer.save.1.json new file mode 100644 index 0000000000000000000000000000000000000000..82190d1a4f82092c2fac79c26c2110194ff8ad58 GIT binary patch literal 4253 zcmc&%-;dii41T}ABGA(Y6usnr0D5P-G?1PL^Fs4w5VGe;+By zvFzAR_Ov|Yhe?qX`SBz3{c18HjPs(>j;@$unhWytWcmu9b0e4&8T_8zF6Q&);-}kL z5LCtp%?}_UmCcBMn29y3l%uw&j5k6!Ga3Es;p6+afBy0L_xox3x~UH-slQc1JFvB8 z%8F>qawAJ83ynUWD<#Xx51;+Vz1aO24@>I<2Nhi@QoSoA7qm2DE%&JDqn}2xk~@(X878O+H5ZO$%rSWQ9g+rVgRH5X22bJS z@u77Ft@@w{XutTFi`74ZV*)TRSLDKkaO_r=rPLdc9PbyhYa4IT_ZRPb5@Yajuq-pe zTFRyKmHNQATubh4qXJgGR>Arkuk}ewsQKj4LFsLuE)-16FxXEz6K3MJVqyh*HKI(wo!y&8;(;gD1H}lC2N3-Fr|^c zp#prH<_k?1jjSu31#n@bXVRtji+ysofupTDezJg9YA5Xu5B7Kfu8k!nZ!?BaGXe2Y znDj%Z9qfc%Vl}p$qpkm#Cap-UdgA`=WRDRrt6ZJb`n~f10;CxzHwmB_RqnP8^0z-GO zS#&QAj%xH@8+}Rn@9q+3Vy9SMmm-KBXsRH;KEicHmuSuOS^6<#t_|{2XkY zkwEm3 zoo#(kIp6f~Ul!)gNV}()?r(82x~bqlnF{Hq25Q3%#Ib#{@=aeS11$z0_OUkmMN#b) og^@e{zfHKc_#XFRyr0zTBB`#wGd`m`*f`;@sb7Ah!qv;wzc5Qq%>V!Z literal 0 HcmV?d00001 diff --git a/corporate/tests/stripe_fixtures/replace_payment_source:Customer.save.2.json b/corporate/tests/stripe_fixtures/replace_payment_source:Customer.save.2.json new file mode 100644 index 0000000000000000000000000000000000000000..572f0751f032d362644d6f0f764c4cb18bd2a55c GIT binary patch literal 1435 zcmb7EZExBz5dPj@Vddi#k3e6o3AGD2v zv)3{>F3Pe{Qc$(dPlqLG9?-Rs@FD({*!KGD-mFGoODADo>Hx)hpLWmB zFFy4yE}7D@sB)NAPb0GuO1n!|S}2Uj+Xd0p+RmT=UY&QlJn2WsZySbw>3x|!nLM<4 zn`_4A5m;;N95cdyI-%8|1N_xqj(HSQ1|jNw$qvZEIG+)`jWRN;Y_Tgvt=*v0abf&E zO0(+ZM!HUD\>P(E*Vu~n$v>0O~CTit?}!iv=n+&cAWe~VR3n;3298b3kFC@AE- z@D*+9S<(x-(U>&4)o((`C)L96y!)Vp>1s=cY0+M=+Ci*21kWPHBJHgp=*bZzl?`*#H0l literal 0 HcmV?d00001 diff --git a/corporate/tests/stripe_fixtures/replace_payment_source:Subscription.create.1.json b/corporate/tests/stripe_fixtures/replace_payment_source:Subscription.create.1.json new file mode 100644 index 0000000000000000000000000000000000000000..0f40d49b895ad65b1d68b76ed9344b8e22de5549 GIT binary patch literal 2160 zcma)8-;WY85PrYEg7n#VAmD+CF-CkaQAtjp&X{KC7N~Z+Yda-}m;2wHc7M=i7a}jP zGt=qJeBU?A)6Hnape(f#fT}QjDN4p6kx=@uykTFpG~LB+3WcvMhS9A%>lzbs>rxB8AWYDJDCK?j6%{9gq46Y zgq|n#)>66Mbd&krY&jjbmv&EYvQJRVP~CNnrX z?hPuBPe0<* zsJ2GWz@%P<$yOg$-=c;tsY7y!Q0ISoPL39vUs8lNLXl2bRYuZ;%HnkDfuMm+T;uunRmvv89BMWWuRWW`1aM=7^FP3X}e->s?+5_m2<0!!ndwIi! zZULIclNVX&q18fL-336XF{8w916Au_jHlZ>13Ez#QR(m-<7gSQtWH__ z#{=mT1C)zXza7ewYe;8xy65=)vpUQ6;HW)&1`In5Rx8)AjbVY*%o)PW+sKLA!{oLn z9QQ6Yy&X_LRTJA|Llj{>Y9y7VnIoL6BTY6S%Byl@&=+F!Zn!MLE8?Ry8p pF1!oLj6O)QAxTgJLwHR79*kecWn7n3y~mpkP#c@e?5488L!s+`dTZJD&)CT)jF`_d3Q>{6M;T|L^gN>a3f`0tAYWvoJ^m(+fK zelPZR6h%UUQQ|h*`n&%Fr3_k|NphW!iZ_sylN94Yx^A^I0kP2JP(^bG4($+ElEx|X zEVM!sxdJ1LFg^>*WPx(U;8uq#s&ly5BXnDq14WkmpHFS5Vb+AtkkRKZ^j#Xz{5ax+ zEcB)F#QXdhT+0hQs?$)B%u28>{Vx)Knyjj|D||RPc;Z-xV0TU6(i#r9p0mk&;dijkq=nVUHfV+Bynl|95)|uxkYSzTl^y?Kkg)9lR%l0FiT!k-? zvKv2QE||{JB)LhiXA|ZXdt;vavM*868mn5d;2cVeq4-Z|5VvpTx+d5e?5488L!s+`dTv`pG=Xxm}Z*rp*ayHp`@*Nir;5*G~+|9y678LJTPCAFWQ zpFj44C=yCKE$*W|z3ESC?ZEp~8QhXryh~*=qr|Wmt{RIjAePo3=xBiw!S`{6u`p(y zrPbgf%pvk1hZkX~%0aCe+}Q90eF--qgl&qVr^s{t%b}gAnKfqXGg9nI-IbG;ha=|F zBe(}1Ra;k`O<-|yZqyYvy|uD5DlLdC`7afI>a?sZ=H!ms3hdj0bmW?h;?A2H`vtCc z#v%)QefyZtUYjX9Tv-dpY7N%xB$~>m#FtmBiFZmz7C40}3|LH$iyPg9 zFOYIKv}jHkPm?&lOKzuOG~(D8abNFC6lMcurCD$$3lA(x{0R->j-_y0hqg}IMdL%| JkT*CCegR(>=i>kX literal 0 HcmV?d00001 diff --git a/corporate/tests/stripe_fixtures/replace_payment_source:Token.create.3.json b/corporate/tests/stripe_fixtures/replace_payment_source:Token.create.3.json new file mode 100644 index 0000000000000000000000000000000000000000..740e49567527aad9bd49a1272413aa36b3b9fed1 GIT binary patch literal 826 zcmaJe?5488L!s+`dT6t=M&(sr1%FAcH7E|p2#HKR?d#6>HJ|Gqd-#wtX5N$uz7 z_hN5*Q6wZ-CGMiFzxzK>%A#|L)YSN>cmt_ZEk(bRE^9+JAQnaws%TC?=(@OE8yqsv z!YH&6Wf(bx{#jTeGn6X^*Ct$1ox_bh!qj=*QRKM)`P4>N%o_9QGWy(wzDo;+A4hy> z2W_c5@jgEW*YX07Y77)wCOJ47{}+irRZ^6OG9Qi)o;cPZSRWb<;x?LU^M$su+7L^6 zd3}GLJw1Lt+zfnUOopfpg!6`?pQ%t9~H*I}^1PTZ|^LBSo z>TU6(i None: - user = self.example_user("iago") + @mock_stripe("Customer.create", "Customer.retrieve", "Customer.save", + "Subscription.create", "Token.create") + def test_replace_payment_source(self, mock5: Mock, mock4: Mock, mock3: Mock, + mock2: Mock, mock1: Mock) -> None: + user = self.example_user("hamlet") self.login(user.email) - Customer.objects.create(realm=user.realm, stripe_customer_id=self.stripe_customer_id) - with patch.object(stripe.Customer, 'save', autospec=True, - side_effect=lambda customer: self.assertEqual(customer.source, "new_token")): - result = self.client_post("/json/billing/sources/change", - {'stripe_token': ujson.dumps("new_token")}) - self.assert_json_success(result) - log_entry = RealmAuditLog.objects.order_by('-id').first() - self.assertEqual(user, log_entry.acting_user) - self.assertEqual(RealmAuditLog.STRIPE_CARD_CHANGED, log_entry.event_type) + self.client_post("/upgrade/", {'stripeToken': stripe_create_token().id, + 'signed_seat_count': self.signed_seat_count, + 'salt': self.salt, + 'plan': Plan.CLOUD_ANNUAL, + 'billing_modality': 'charge_automatically'}) + # Try replacing with a valid card + stripe_token = stripe_create_token(card_number='5555555555554444').id + response = self.client_post("/json/billing/sources/change", + {'stripe_token': ujson.dumps(stripe_token)}) + self.assert_json_success(response) + number_of_sources = 0 + for stripe_source in stripe_get_customer(Customer.objects.first().stripe_customer_id).sources: + self.assertEqual(cast(stripe.Card, stripe_source).last4, '4444') + number_of_sources += 1 + self.assertEqual(number_of_sources, 1) + audit_log_entry = RealmAuditLog.objects.order_by('-id') \ + .values_list('acting_user', 'event_type').first() + self.assertEqual(audit_log_entry, (user.id, RealmAuditLog.STRIPE_CARD_CHANGED)) + RealmAuditLog.objects.filter(acting_user=user).delete() - @patch("stripe.Customer.retrieve", side_effect=mock_customer_with_subscription) - def test_replace_payment_source_with_stripe_error(self, mock_retrieve_customer: Mock) -> None: - user = self.example_user("iago") - self.login(user.email) - Customer.objects.create(realm=user.realm, stripe_customer_id=self.stripe_customer_id) - with patch.object(stripe.Customer, 'save', autospec=True, - side_effect=stripe.error.StripeError('message', json_body={})): + # Try replacing with an invalid card + stripe_token = stripe_create_token(card_number='4000000000009987').id + with patch("corporate.lib.stripe.billing_logger.error") as mock_billing_logger: response = self.client_post("/json/billing/sources/change", - {'stripe_token': ujson.dumps("new_token")}) - self.assertEqual(ujson.loads(response.content)['error_description'], 'other stripe error') - self.assert_json_error_contains(response, 'Something went wrong. Please contact') - self.assertFalse(RealmAuditLog.objects.filter( - event_type=RealmAuditLog.STRIPE_CARD_CHANGED).exists()) + {'stripe_token': ujson.dumps(stripe_token)}) + mock_billing_logger.assert_called() + self.assertEqual(ujson.loads(response.content)['error_description'], 'card error') + self.assert_json_error_contains(response, 'Your card was declined') + number_of_sources = 0 + for stripe_source in stripe_get_customer(Customer.objects.first().stripe_customer_id).sources: + self.assertEqual(cast(stripe.Card, stripe_source).last4, '4444') + number_of_sources += 1 + self.assertEqual(number_of_sources, 1) + self.assertFalse(RealmAuditLog.objects.filter(event_type=RealmAuditLog.STRIPE_CARD_CHANGED).exists()) @patch("stripe.Customer.create", side_effect=mock_create_customer) @patch("stripe.Subscription.create", side_effect=mock_create_subscription) diff --git a/stubs/stripe/__init__.pyi b/stubs/stripe/__init__.pyi index 77753ee45f..00d739e125 100644 --- a/stubs/stripe/__init__.pyi +++ b/stubs/stripe/__init__.pyi @@ -12,6 +12,7 @@ class Customer: created: int id: str source: str + sources: List[Union[Card, Source]] subscriptions: SubscriptionListObject coupon: str account_balance: int