-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2577] Fix strategy: expect membership tasks to exist
- Loading branch information
1 parent
0e522d6
commit 40e16a1
Showing
3 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -247,6 +247,90 @@ def test_integration(self) -> None: | |
assert latest_log | ||
self.assertEqual(latest_log.details, "Email was cancelled") | ||
|
||
@override_settings(FLAGS={"EMAIL_MODULE": [("boolean", True)]}) | ||
def test_integration_when_removing_membership_task(self) -> None: | ||
# Arrange | ||
self._setUpUsersAndLogin() | ||
|
||
membership = Membership.objects.create( | ||
name="Test Membership", | ||
variant="partner", | ||
registration_code="test-beta-code-test", | ||
agreement_start=date.today(), | ||
agreement_end=date.today() + timedelta(days=365), | ||
contribution_type="financial", | ||
workshops_without_admin_fee_per_agreement=10, | ||
public_instructor_training_seats=25, | ||
additional_public_instructor_training_seats=3, | ||
) | ||
Member.objects.create( | ||
membership=membership, | ||
organization=self.org_beta, | ||
role=MemberRole.objects.first(), | ||
) | ||
billing_contact_role = MembershipPersonRole.objects.create( | ||
name="billing_contact" | ||
) | ||
task = MembershipTask.objects.create( | ||
person=self.hermione, | ||
membership=membership, | ||
role=billing_contact_role, | ||
) | ||
|
||
signal = NEW_MEMBERSHIP_ONBOARDING_SIGNAL_NAME | ||
template = EmailTemplate.objects.create( | ||
name="Test Email Template", | ||
signal=signal, | ||
from_header="[email protected]", | ||
cc_header=["[email protected]"], | ||
bcc_header=[], | ||
subject="Greetings", | ||
body="Hello! Nice to meet **you**.", | ||
) | ||
request = RequestFactory().get("/") | ||
|
||
with patch( | ||
"emails.actions.base_action.messages_action_scheduled" | ||
) as mock_action_scheduled: | ||
run_new_membership_onboarding_strategy( | ||
new_membership_onboarding_strategy(membership), | ||
request=request, | ||
membership=membership, | ||
) | ||
scheduled_email = ScheduledEmail.objects.get(template=template) | ||
|
||
url = reverse("membership_tasks", args=[membership.pk]) | ||
|
||
# Act | ||
data = { | ||
"form-TOTAL_FORMS": "1", | ||
"form-INITIAL_FORMS": "1", | ||
"form-MIN_NUM_FORMS": "0", | ||
"form-MAX_NUM_FORMS": "1000", | ||
"form-0-membership": membership.pk, | ||
"form-0-person": task.person.pk, | ||
"form-0-role": task.role.pk, | ||
"form-0-id": task.pk, | ||
"form-0-DELETE": "on", | ||
} | ||
rv = self.client.post(url, data=data) | ||
|
||
# Arrange | ||
mock_action_scheduled.assert_called_once() | ||
self.assertEqual(rv.status_code, 302) | ||
self.assertEqual( | ||
MembershipTask.objects.filter(membership=membership).count(), 0 | ||
) | ||
scheduled_email.refresh_from_db() | ||
self.assertEqual(scheduled_email.state, ScheduledEmailStatus.CANCELLED) | ||
latest_log = ( | ||
ScheduledEmailLog.objects.filter(scheduled_email=scheduled_email) | ||
.order_by("-created_at") | ||
.first() | ||
) | ||
assert latest_log | ||
self.assertEqual(latest_log.details, "Email was cancelled") | ||
|
||
@override_settings(FLAGS={"EMAIL_MODULE": [("boolean", True)]}) | ||
def test_integration__not_removed_because_of_related_objects(self) -> None: | ||
# Arrange | ||
|
This file contains 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