Skip to content

Commit d045615

Browse files
fix: Remove tos input defaults and separate out more new vs deprecated
1 parent 7bc85a9 commit d045615

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

codecov_auth/commands/owner/interactors/save_terms_agreement.py

+33-16
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,28 @@ def validate_deprecated(self, input: TermsAgreementInput) -> None:
3232
raise Unauthenticated()
3333

3434
def validate(self, input: TermsAgreementInput) -> None:
35-
if not input.business_email:
36-
raise ValidationError("Email is required")
37-
if not input.name:
38-
raise ValidationError("Name is required")
3935
if not self.current_user.is_authenticated:
4036
raise Unauthenticated()
4137

42-
def update_terms_agreement(self, input: TermsAgreementInput) -> None:
38+
def update_terms_agreement_deprecated(self, input: TermsAgreementInput) -> None:
4339
self.current_user.terms_agreement = input.terms_agreement
4440
self.current_user.terms_agreement_at = timezone.now()
41+
self.current_user.customer_intent = input.customer_intent
4542
self.current_user.email_opt_in = input.marketing_consent
43+
self.current_user.save()
44+
45+
if input.business_email and input.business_email != "":
46+
self.current_user.email = input.business_email
47+
self.current_user.save()
48+
49+
if input.marketing_consent:
50+
self.send_data_to_marketo()
51+
52+
def update_terms_agreement(self, input: TermsAgreementInput) -> None:
53+
self.current_user.terms_agreement = input.terms_agreement
54+
self.current_user.terms_agreement_at = timezone.now()
4655
self.current_user.name = input.name
56+
self.current_user.email_opt_in = input.marketing_consent
4757
self.current_user.save()
4858

4959
if input.business_email and input.business_email != "":
@@ -61,15 +71,22 @@ def send_data_to_marketo(self) -> None:
6171

6272
@sync_to_async
6373
def execute(self, input: Any) -> None:
64-
typed_input = TermsAgreementInput(
65-
business_email=input.get("business_email", ""),
66-
terms_agreement=input.get("terms_agreement", False),
67-
marketing_consent=input.get("marketing_consent", False),
68-
customer_intent=input.get("customer_intent"),
69-
name=input.get("name", ""),
70-
)
71-
if input.get("customer_intent"):
72-
self.validate_deprecated(typed_input)
73-
else:
74+
if input.get("name"):
75+
typed_input = TermsAgreementInput(
76+
business_email=input.get("business_email"),
77+
terms_agreement=input.get("terms_agreement"),
78+
marketing_consent=input.get("marketing_consent"),
79+
name=input.get("name"),
80+
)
7481
self.validate(typed_input)
75-
return self.update_terms_agreement(typed_input)
82+
self.update_terms_agreement(typed_input)
83+
# this handles the deprecated inputs
84+
else:
85+
typed_input = TermsAgreementInput(
86+
business_email=input.get("business_email"),
87+
terms_agreement=input.get("terms_agreement"),
88+
marketing_consent=input.get("marketing_consent"),
89+
customer_intent=input.get("customer_intent"),
90+
)
91+
self.validate_deprecated(typed_input)
92+
self.update_terms_agreement_deprecated(typed_input)

codecov_auth/commands/owner/interactors/tests/test_save_terms_agreement.py

-17
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,6 @@ def test_update_owner_and_user_when_email_and_name_are_not_empty(self):
199199
assert self.current_user.email == "[email protected]"
200200
assert self.current_user.name == "codecov-user"
201201

202-
def test_validation_error_when_email_invalid(self):
203-
with pytest.raises(ValidationError):
204-
self.execute(
205-
current_user=self.current_user,
206-
input={"name": "codecov-user", "terms_agreement": True},
207-
)
208-
209-
def test_validation_error_when_name_invalid(self):
210-
with pytest.raises(ValidationError):
211-
self.execute(
212-
current_user=self.current_user,
213-
input={
214-
"business_email": "[email protected]",
215-
"terms_agreement": True,
216-
},
217-
)
218-
219202
def test_user_is_not_authenticated(self):
220203
with pytest.raises(Unauthenticated):
221204
self.execute(

0 commit comments

Comments
 (0)