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

Commit 2200d3a

Browse files
fix: Fix wrong variable and modify tests
1 parent adea2a2 commit 2200d3a

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

codecov_auth/commands/owner/interactors/save_terms_agreement.py

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

2323
def validate(self, input: TermsAgreementInput) -> None:
24-
if not self.current_user.business_email:
25-
raise ValidationError("Business email is required")
26-
if not self.current_user.name:
24+
print("qwerty input: ", input)
25+
if not input.business_email:
26+
raise ValidationError("Email is required")
27+
if not input.name:
2728
raise ValidationError("Name is required")
2829
if not self.current_user.is_authenticated:
2930
raise Unauthenticated()
@@ -56,5 +57,5 @@ def execute(self, input: Any) -> None:
5657
marketing_consent=input.get("marketing_consent", False),
5758
name=input.get("name", ""),
5859
)
59-
self.validate(input)
60+
self.validate(typed_input)
6061
return self.update_terms_agreement(typed_input)

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

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ def execute(self, current_user, input=None):
3636
def test_update_user_when_agreement_is_false(self):
3737
self.execute(
3838
current_user=self.current_user,
39-
input={"terms_agreement": False, "customer_intent": "Business"},
39+
input={
40+
"business_email": "[email protected]",
41+
"name": "codecov-user",
42+
"terms_agreement": False,
43+
},
4044
)
4145
before_refresh_business_email = self.current_user.email
4246

@@ -50,7 +54,11 @@ def test_update_user_when_agreement_is_false(self):
5054
def test_update_user_when_agreement_is_true(self):
5155
self.execute(
5256
current_user=self.current_user,
53-
input={"terms_agreement": True, "customer_intent": "Business"},
57+
input={
58+
"business_email": "[email protected]",
59+
"name": "codecov-user",
60+
"terms_agreement": True,
61+
},
5462
)
5563
before_refresh_business_email = self.current_user.email
5664

@@ -61,13 +69,13 @@ def test_update_user_when_agreement_is_true(self):
6169
assert self.current_user.email == before_refresh_business_email
6270

6371
@freeze_time("2022-01-01T00:00:00")
64-
def test_update_owner_and_user_when_email_is_not_empty(self):
72+
def test_update_owner_and_user_when_email_and_name_are_not_empty(self):
6573
self.execute(
6674
current_user=self.current_user,
6775
input={
6876
"business_email": "[email protected]",
77+
"name": "codecov-user",
6978
"terms_agreement": True,
70-
"customer_intent": "Business",
7179
},
7280
)
7381

@@ -76,12 +84,23 @@ def test_update_owner_and_user_when_email_is_not_empty(self):
7684

7785
self.current_user.refresh_from_db()
7886
assert self.current_user.email == "[email protected]"
87+
assert self.current_user.name == "codecov-user"
7988

80-
def test_validation_error_when_customer_intent_invalid(self):
89+
def test_validation_error_when_email_invalid(self):
8190
with pytest.raises(ValidationError):
8291
self.execute(
8392
current_user=self.current_user,
84-
input={"terms_agreement": None, "customer_intent": "invalid"},
93+
input={"name": "codecov-user", "terms_agreement": True},
94+
)
95+
96+
def test_validation_error_when_name_invalid(self):
97+
with pytest.raises(ValidationError):
98+
self.execute(
99+
current_user=self.current_user,
100+
input={
101+
"business_email": "[email protected]",
102+
"terms_agreement": True,
103+
},
85104
)
86105

87106
def test_user_is_not_authenticated(self):
@@ -90,18 +109,19 @@ def test_user_is_not_authenticated(self):
90109
current_user=AnonymousUser(),
91110
input={
92111
"business_email": "[email protected]",
112+
"name": "codecov-user",
93113
"terms_agreement": True,
94-
"customer_intent": "Business",
95114
},
96115
)
97116

98117
def test_email_opt_in_saved_in_db(self):
99118
self.execute(
100119
current_user=self.current_user,
101120
input={
121+
"business_email": "[email protected]",
122+
"name": "codecov-user",
102123
"terms_agreement": True,
103124
"marketing_consent": True,
104-
"customer_intent": "Business",
105125
},
106126
)
107127
self.current_user.refresh_from_db()
@@ -114,9 +134,10 @@ def test_marketo_called_only_with_consent(self, mock_send_data_to_marketo):
114134
self.execute(
115135
current_user=self.current_user,
116136
input={
137+
"business_email": "[email protected]",
138+
"name": "codecov-user",
117139
"terms_agreement": True,
118140
"marketing_consent": True,
119-
"customer_intent": "Business",
120141
},
121142
)
122143

@@ -129,9 +150,10 @@ def test_marketo_not_called_without_consent(self, mock_send_data_to_marketo):
129150
self.execute(
130151
current_user=self.current_user,
131152
input={
153+
"business_email": "[email protected]",
154+
"name": "codecov-user",
132155
"terms_agreement": True,
133156
"marketing_consent": False,
134-
"customer_intent": "Business",
135157
},
136158
)
137159

utils/test_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def app(self) -> str:
4545
migrate_to = None
4646

4747
def setUp(self) -> None:
48-
assert self.migrate_from and self.migrate_to, (
49-
"TestCase '{}' must define migrate_from and migrate_to properties".format(
50-
type(self).__name__
51-
)
48+
assert (
49+
self.migrate_from and self.migrate_to
50+
), "TestCase '{}' must define migrate_from and migrate_to properties".format(
51+
type(self).__name__
5252
)
5353
self.migrate_from = [(self.app, self.migrate_from)]
5454
self.migrate_to = [(self.app, self.migrate_to)]

0 commit comments

Comments
 (0)