@@ -32,8 +32,10 @@ def execute(self, current_user, input=None):
3232 input = real_input ,
3333 )
3434
35+ #### Start of older tests
36+
3537 @freeze_time ("2022-01-01T00:00:00" )
36- def test_update_user_when_agreement_is_false (self ):
38+ def test_deprecated_update_user_when_agreement_is_false (self ):
3739 self .execute (
3840 current_user = self .current_user ,
3941 input = {"terms_agreement" : False , "customer_intent" : "Business" },
@@ -47,7 +49,7 @@ def test_update_user_when_agreement_is_false(self):
4749 assert self .current_user .email == before_refresh_business_email
4850
4951 @freeze_time ("2022-01-01T00:00:00" )
50- def test_update_user_when_agreement_is_true (self ):
52+ def test_deprecated_update_user_when_agreement_is_true (self ):
5153 self .execute (
5254 current_user = self .current_user ,
5355 input = {"terms_agreement" : True , "customer_intent" : "Business" },
@@ -61,7 +63,7 @@ def test_update_user_when_agreement_is_true(self):
6163 assert self .current_user .email == before_refresh_business_email
6264
6365 @freeze_time ("2022-01-01T00:00:00" )
64- def test_update_owner_and_user_when_email_is_not_empty (self ):
66+ def test_deprecated_update_owner_and_user_when_email_is_not_empty (self ):
6567 self .execute (
6668 current_user = self .current_user ,
6769 input = {
@@ -77,14 +79,14 @@ def test_update_owner_and_user_when_email_is_not_empty(self):
7779 self .current_user .refresh_from_db ()
7880 assert self .
current_user .
email == "[email protected] " 7981
80- def test_validation_error_when_customer_intent_invalid (self ):
82+ def test_deprecated_validation_error_when_customer_intent_invalid (self ):
8183 with pytest .raises (ValidationError ):
8284 self .execute (
8385 current_user = self .current_user ,
8486 input = {"terms_agreement" : None , "customer_intent" : "invalid" },
8587 )
8688
87- def test_user_is_not_authenticated (self ):
89+ def test_deprecated_user_is_not_authenticated (self ):
8890 with pytest .raises (Unauthenticated ):
8991 self .execute (
9092 current_user = AnonymousUser (),
@@ -95,7 +97,7 @@ def test_user_is_not_authenticated(self):
9597 },
9698 )
9799
98- def test_email_opt_in_saved_in_db (self ):
100+ def test_deprecated_email_opt_in_saved_in_db (self ):
99101 self .execute (
100102 current_user = self .current_user ,
101103 input = {
@@ -110,7 +112,9 @@ def test_email_opt_in_saved_in_db(self):
110112 @patch (
111113 "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo"
112114 )
113- def test_marketo_called_only_with_consent (self , mock_send_data_to_marketo ):
115+ def test_deprecated_marketo_called_only_with_consent (
116+ self , mock_send_data_to_marketo
117+ ):
114118 self .execute (
115119 current_user = self .current_user ,
116120 input = {
@@ -125,7 +129,9 @@ def test_marketo_called_only_with_consent(self, mock_send_data_to_marketo):
125129 @patch (
126130 "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo"
127131 )
128- def test_marketo_not_called_without_consent (self , mock_send_data_to_marketo ):
132+ def test_deprecated_marketo_not_called_without_consent (
133+ self , mock_send_data_to_marketo
134+ ):
129135 self .execute (
130136 current_user = self .current_user ,
131137 input = {
@@ -136,3 +142,115 @@ def test_marketo_not_called_without_consent(self, mock_send_data_to_marketo):
136142 )
137143
138144 mock_send_data_to_marketo .assert_not_called ()
145+
146+ #### End of older tests
147+
148+ @freeze_time ("2022-01-01T00:00:00" )
149+ def test_update_user_when_agreement_is_false (self ):
150+ self .execute (
151+ current_user = self .current_user ,
152+ input = {
153+ "business_email" :
"[email protected] " ,
154+ "name" : "codecov-user" ,
155+ "terms_agreement" : False ,
156+ },
157+ )
158+ before_refresh_business_email = self .current_user .email
159+
160+ assert self .current_user .terms_agreement == False
161+ assert self .current_user .terms_agreement_at == self .updated_at
162+
163+ self .current_user .refresh_from_db ()
164+ assert self .current_user .email == before_refresh_business_email
165+
166+ @freeze_time ("2022-01-01T00:00:00" )
167+ def test_update_user_when_agreement_is_true (self ):
168+ self .execute (
169+ current_user = self .current_user ,
170+ input = {
171+ "business_email" :
"[email protected] " ,
172+ "name" : "codecov-user" ,
173+ "terms_agreement" : True ,
174+ },
175+ )
176+ before_refresh_business_email = self .current_user .email
177+
178+ assert self .current_user .terms_agreement == True
179+ assert self .current_user .terms_agreement_at == self .updated_at
180+
181+ self .current_user .refresh_from_db ()
182+ assert self .current_user .email == before_refresh_business_email
183+
184+ @freeze_time ("2022-01-01T00:00:00" )
185+ def test_update_owner_and_user_when_email_and_name_are_not_empty (self ):
186+ self .execute (
187+ current_user = self .current_user ,
188+ input = {
189+ "business_email" :
"[email protected] " ,
190+ "name" : "codecov-user" ,
191+ "terms_agreement" : True ,
192+ },
193+ )
194+
195+ assert self .current_user .terms_agreement == True
196+ assert self .current_user .terms_agreement_at == self .updated_at
197+
198+ self .current_user .refresh_from_db ()
199+ assert self .
current_user .
email == "[email protected] " 200+ assert self .current_user .name == "codecov-user"
201+
202+ def test_user_is_not_authenticated (self ):
203+ with pytest .raises (Unauthenticated ):
204+ self .execute (
205+ current_user = AnonymousUser (),
206+ input = {
207+ "business_email" :
"[email protected] " ,
208+ "name" : "codecov-user" ,
209+ "terms_agreement" : True ,
210+ },
211+ )
212+
213+ def test_email_opt_in_saved_in_db (self ):
214+ self .execute (
215+ current_user = self .current_user ,
216+ input = {
217+ "business_email" :
"[email protected] " ,
218+ "name" : "codecov-user" ,
219+ "terms_agreement" : True ,
220+ "marketing_consent" : True ,
221+ },
222+ )
223+ self .current_user .refresh_from_db ()
224+ assert self .current_user .email_opt_in == True
225+
226+ @patch (
227+ "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo"
228+ )
229+ def test_marketo_called_only_with_consent (self , mock_send_data_to_marketo ):
230+ self .execute (
231+ current_user = self .current_user ,
232+ input = {
233+ "business_email" :
"[email protected] " ,
234+ "name" : "codecov-user" ,
235+ "terms_agreement" : True ,
236+ "marketing_consent" : True ,
237+ },
238+ )
239+
240+ mock_send_data_to_marketo .assert_called_once ()
241+
242+ @patch (
243+ "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo"
244+ )
245+ def test_marketo_not_called_without_consent (self , mock_send_data_to_marketo ):
246+ self .execute (
247+ current_user = self .current_user ,
248+ input = {
249+ "business_email" :
"[email protected] " ,
250+ "name" : "codecov-user" ,
251+ "terms_agreement" : True ,
252+ "marketing_consent" : False ,
253+ },
254+ )
255+
256+ mock_send_data_to_marketo .assert_not_called ()
0 commit comments