Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions TWLight/emails/management/commands/cleanup_email.py

This file was deleted.

66 changes: 0 additions & 66 deletions TWLight/emails/models.py

This file was deleted.

39 changes: 0 additions & 39 deletions TWLight/emails/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ class RejectionNotification(template_mail.TemplateMail):
name = "rejection_notification"


class SurveyActiveUser(template_mail.TemplateMail):
name = "survey_active_user"


class Test(template_mail.TemplateMail):
name = "test"

Expand Down Expand Up @@ -207,41 +203,6 @@ def send_user_renewal_notice_emails(sender, **kwargs):
return bool(result)


def send_survey_active_user_email(connection=email_connection(), **kwargs):
"""
Any time the related managment command is run, this sends a survey
invitation to qualifying editors.
"""
user_email = kwargs["user_email"]
user_lang = kwargs["user_lang"]
survey_id = kwargs["survey_id"]
survey_langs = kwargs["survey_langs"]

# Default survey language is english
survey_lang = "en"

# Set survey language to user language if available
if user_lang in survey_langs:
survey_lang = user_lang

base_url = "https://wikimediafoundation.limesurvey.net/"
link = "{base}{id}?lang={lang}".format(
base=base_url, id=survey_id, lang=survey_lang
)

template_email = SurveyActiveUser()

email = template_email.make_email_object(
user_email,
{
"lang": user_lang,
"link": link,
},
)
message = Message.from_email_message(email)
_safe_send_message(message, connection=connection)


def send_test(connection=email_connection(), **kwargs):
user_email = kwargs["email"]
template_email = Test()
Expand Down
23 changes: 0 additions & 23 deletions TWLight/emails/templates/emails/survey_active_user-body-html.html

This file was deleted.

26 changes: 0 additions & 26 deletions TWLight/emails/templates/emails/survey_active_user-body-text.html

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion TWLight/emails/templates/emails/test-body-html.html

This file was deleted.

1 change: 0 additions & 1 deletion TWLight/emails/templates/emails/test-body-text.html

This file was deleted.

1 change: 0 additions & 1 deletion TWLight/emails/templates/emails/test-subject.html

This file was deleted.

150 changes: 0 additions & 150 deletions TWLight/emails/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
send_approval_notification_email,
send_rejection_notification_email,
send_user_renewal_notice_emails,
send_survey_active_user_email,
)


Expand Down Expand Up @@ -827,152 +826,3 @@ def test_send_coordinator_reminder_email(self):
self.assertIn("1 pending application", mail.outbox[0].body)
self.assertIn("1 under discussion application", mail.outbox[0].body)
self.assertIn("1 approved application", mail.outbox[0].body)


class SurveyActiveUsersEmailTest(TestCase):
@classmethod
def setUpTestData(cls):
"""
Creates a survey-eligible user, several ineligible users, and one already sent message.
Returns
-------
None
"""

now = timezone.now()

eligible = EditorFactory(user__email="editor@example.com")
eligible.wp_not_blocked = True
eligible.wp_bundle_eligible = True
eligible.wp_account_old_enough = True
eligible.wp_registered = now - timedelta(days=182)
eligible.wp_enough_edits = True
eligible.user.userprofile.terms_of_use = True
eligible.user.userprofile.save()
eligible.user.last_login = now
eligible.user.save()
eligible.save()
cls.eligible = eligible.user

blocked = EditorFactory(user__email="blocked@example.com")
blocked.wp_not_blocked = False
blocked.wp_bundle_eligible = True
blocked.wp_account_old_enough = True
blocked.wp_registered = now - timedelta(days=182)
blocked.wp_enough_edits = True
blocked.user.userprofile.terms_of_use = True
blocked.user.userprofile.save()
blocked.user.last_login = now
blocked.user.save()
blocked.save()

already_sent = EditorFactory(user__email="alreadysent@example.com")
already_sent.wp_not_blocked = True
already_sent.wp_bundle_eligible = True
already_sent.wp_account_old_enough = True
already_sent.wp_registered = now - timedelta(days=182)
already_sent.wp_enough_edits = True
already_sent.user.userprofile.terms_of_use = True
already_sent.user.userprofile.save()
already_sent.user.last_login = now
already_sent.user.save()
already_sent.save()

wmf_email = EditorFactory(user__email="editor@wikimedia.org")
wmf_email.wp_not_blocked = True
wmf_email.wp_bundle_eligible = True
wmf_email.wp_account_old_enough = True
wmf_email.wp_registered = now - timedelta(days=182)
wmf_email.wp_enough_edits = True
wmf_email.user.userprofile.terms_of_use = True
wmf_email.user.userprofile.save()
wmf_email.user.last_login = now
wmf_email.user.save()
wmf_email.save()

too_new_at_login = EditorFactory(user__email="toonew@example.com")
too_new_at_login.wp_not_blocked = True
too_new_at_login.wp_bundle_eligible = True
too_new_at_login.wp_account_old_enough = True
too_new_at_login.wp_registered = now - timedelta(days=182)
too_new_at_login.wp_enough_edits = True
too_new_at_login.user.userprofile.terms_of_use = True
too_new_at_login.user.userprofile.save()
too_new_at_login.user.last_login = now - timedelta(days=30)
too_new_at_login.user.save()
too_new_at_login.save()

not_enough_edits = EditorFactory(user__email="notenoughedits@example.com")
not_enough_edits.wp_not_blocked = True
not_enough_edits.wp_bundle_eligible = True
not_enough_edits.wp_account_old_enough = True
not_enough_edits.wp_registered = now - timedelta(days=182)
not_enough_edits.wp_enough_edits = False
not_enough_edits.user.userprofile.terms_of_use = True
not_enough_edits.user.userprofile.save()
not_enough_edits.user.last_login = now
not_enough_edits.user.save()
not_enough_edits.save()

inactive = EditorFactory(user__email="inactive@example.com")
inactive.wp_not_blocked = True
inactive.wp_bundle_eligible = True
inactive.wp_account_old_enough = True
inactive.wp_registered = now - timedelta(days=182)
inactive.wp_enough_edits = True
inactive.user.userprofile.terms_of_use = True
inactive.user.userprofile.save()
inactive.user.last_login = now
inactive.user.is_active = False
inactive.user.save()
inactive.save()

staff = EditorFactory(user__email="staff@example.com")
staff.wp_not_blocked = True
staff.wp_bundle_eligible = True
staff.wp_account_old_enough = True
staff.wp_registered = now - timedelta(days=182)
staff.wp_enough_edits = True
staff.user.userprofile.terms_of_use = True
staff.user.userprofile.save()
staff.user.last_login = now
staff.user.is_staff = True
staff.user.save()
staff.save()

superuser = EditorFactory(user__email="superuser@example.com")
superuser.wp_not_blocked = True
superuser.wp_bundle_eligible = True
superuser.wp_account_old_enough = True
superuser.wp_registered = now - timedelta(days=182)
superuser.wp_enough_edits = True
superuser.user.userprofile.terms_of_use = True
superuser.user.userprofile.save()
superuser.user.last_login = now
superuser.user.is_superuser = True
superuser.user.save()
superuser.save()

# Use the same override as djmail itself since the command dynamically changes the backend
@override_settings(
EMAIL_BACKEND="djmail.backends.default.EmailBackend",
DJMAIL_REAL_BACKEND="django.core.mail.backends.locmem.EmailBackend",
)
def test_survey_active_users_command(self):
# pre-send an email to the "alreadysent" editor
already_sent_msg = mail.EmailMessage(
"The Wikipedia Library needs your help!",
"Body",
"sender@example.com",
["alreadysent@example.com"],
)
already_sent_msg.send()

call_command(
"survey_active_users",
"000001",
"en",
backend="djmail.backends.default.EmailBackend",
)
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(mail.outbox[1].to, [self.eligible.email])
Loading
Loading