This repository was archived by the owner on Jun 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
feat: Update with email opt in #884
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| from asgiref.sync import async_to_sync | ||
| from django.contrib.auth.models import AnonymousUser | ||
|
|
@@ -24,6 +26,7 @@ def execute( | |
| input={ | ||
| "business_email": None, | ||
| "terms_agreement": False, | ||
| "marketing_consent": False, | ||
| }, | ||
| ): | ||
| return SaveTermsAgreementInteractor(None, "github", current_user).execute( | ||
|
|
@@ -75,13 +78,6 @@ def test_update_owner_and_user_when_email_is_not_empty(self): | |
| self.current_user.refresh_from_db() | ||
| assert self.current_user.email == "[email protected]" | ||
|
|
||
| def test_validation_error_when_terms_is_none(self): | ||
| with pytest.raises(ValidationError): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={"terms_agreement": None, "customer_intent": "Business"}, | ||
| ) | ||
|
|
||
| def test_validation_error_when_customer_intent_invalid(self): | ||
| with pytest.raises(ValidationError): | ||
| self.execute( | ||
|
|
@@ -99,3 +95,45 @@ def test_user_is_not_authenticated(self): | |
| "customer_intent": "Business", | ||
| }, | ||
| ) | ||
|
|
||
| def test_email_opt_in_saved_in_db(self): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
| "terms_agreement": True, | ||
| "marketing_consent": True, | ||
| "customer_intent": "Business", | ||
| }, | ||
| ) | ||
| self.current_user.refresh_from_db() | ||
| assert self.current_user.email_opt_in == True | ||
|
|
||
| @patch( | ||
| "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo" | ||
| ) | ||
| def test_marketo_called_only_with_consent(self, mock_send_data_to_marketo): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
| "terms_agreement": True, | ||
| "marketing_consent": True, | ||
| "customer_intent": "Business", | ||
| }, | ||
| ) | ||
|
|
||
| mock_send_data_to_marketo.assert_called_once() | ||
|
|
||
| @patch( | ||
| "codecov_auth.commands.owner.interactors.save_terms_agreement.SaveTermsAgreementInteractor.send_data_to_marketo" | ||
| ) | ||
| def test_marketo_not_called_without_consent(self, mock_send_data_to_marketo): | ||
| self.execute( | ||
| current_user=self.current_user, | ||
| input={ | ||
| "terms_agreement": True, | ||
| "marketing_consent": False, | ||
| "customer_intent": "Business", | ||
| }, | ||
| ) | ||
|
|
||
| mock_send_data_to_marketo.assert_not_called() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per Rola, condition is never used so this is dead code removal