Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit eedcb63

Browse files
committed
Merge branch 'main' of github.com:codecov/codecov-api into joseph/fix-sql-query
2 parents f57a0f3 + 3b84808 commit eedcb63

File tree

14 files changed

+1300
-294
lines changed

14 files changed

+1300
-294
lines changed

codecov_auth/commands/owner/interactors/save_terms_agreement.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ class SaveTermsAgreementInteractor(BaseInteractor):
2121
requires_service = False
2222

2323
def validate(self, input: TermsAgreementInput):
24-
if input.terms_agreement is None:
25-
raise ValidationError("Terms of agreement cannot be null")
26-
if input.customer_intent and input.customer_intent not in [
27-
"Business",
28-
"BUSINESS",
29-
"Personal",
30-
"PERSONAL",
31-
]:
24+
valid_customer_intents = ["Business", "BUSINESS", "Personal", "PERSONAL"]
25+
if (
26+
input.customer_intent
27+
and input.customer_intent not in valid_customer_intents
28+
):
3229
raise ValidationError("Invalid customer intent provided")
3330
if not self.current_user.is_authenticated:
3431
raise Unauthenticated()
@@ -37,13 +34,15 @@ def update_terms_agreement(self, input: TermsAgreementInput):
3734
self.current_user.terms_agreement = input.terms_agreement
3835
self.current_user.terms_agreement_at = timezone.now()
3936
self.current_user.customer_intent = input.customer_intent
37+
self.current_user.email_opt_in = input.marketing_consent
4038
self.current_user.save()
4139

42-
if input.business_email is not None and input.business_email != "":
40+
if input.business_email and input.business_email != "":
4341
self.current_user.email = input.business_email
4442
self.current_user.save()
4543

46-
self.send_data_to_marketo()
44+
if input.marketing_consent:
45+
self.send_data_to_marketo()
4746

4847
def send_data_to_marketo(self):
4948
event_data = {

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

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from unittest.mock import patch
2+
13
import pytest
24
from asgiref.sync import async_to_sync
35
from django.contrib.auth.models import AnonymousUser
@@ -24,6 +26,7 @@ def execute(
2426
input={
2527
"business_email": None,
2628
"terms_agreement": False,
29+
"marketing_consent": False,
2730
},
2831
):
2932
return SaveTermsAgreementInteractor(None, "github", current_user).execute(
@@ -75,13 +78,6 @@ def test_update_owner_and_user_when_email_is_not_empty(self):
7578
self.current_user.refresh_from_db()
7679
assert self.current_user.email == "[email protected]"
7780

78-
def test_validation_error_when_terms_is_none(self):
79-
with pytest.raises(ValidationError):
80-
self.execute(
81-
current_user=self.current_user,
82-
input={"terms_agreement": None, "customer_intent": "Business"},
83-
)
84-
8581
def test_validation_error_when_customer_intent_invalid(self):
8682
with pytest.raises(ValidationError):
8783
self.execute(
@@ -99,3 +95,45 @@ def test_user_is_not_authenticated(self):
9995
"customer_intent": "Business",
10096
},
10197
)
98+
99+
def test_email_opt_in_saved_in_db(self):
100+
self.execute(
101+
current_user=self.current_user,
102+
input={
103+
"terms_agreement": True,
104+
"marketing_consent": True,
105+
"customer_intent": "Business",
106+
},
107+
)
108+
self.current_user.refresh_from_db()
109+
assert self.current_user.email_opt_in == True
110+
111+
@patch(
112+
"codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo"
113+
)
114+
def test_marketo_called_only_with_consent(self, mock_send_data_to_marketo):
115+
self.execute(
116+
current_user=self.current_user,
117+
input={
118+
"terms_agreement": True,
119+
"marketing_consent": True,
120+
"customer_intent": "Business",
121+
},
122+
)
123+
124+
mock_send_data_to_marketo.assert_called_once()
125+
126+
@patch(
127+
"codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo"
128+
)
129+
def test_marketo_not_called_without_consent(self, mock_send_data_to_marketo):
130+
self.execute(
131+
current_user=self.current_user,
132+
input={
133+
"terms_agreement": True,
134+
"marketing_consent": False,
135+
"customer_intent": "Business",
136+
},
137+
)
138+
139+
mock_send_data_to_marketo.assert_not_called()

graphql_api/tests/test_bundle_analysis_measurements.py

Lines changed: 783 additions & 263 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)