Esempio n. 1
0
def test_inactive_user(mock_send_mail):
    user = UserFactory(notify_by_message=True, notify_by_email=True,
                       is_active=False)
    notify.notify_users(notify.Notifications.ROLE_CHANGED, [user],
                        'Test subject', 'tests/test-message.html', {})
    # test that we don't send a message or an email
    assert Message.objects.for_user(user).count() == 0
    assert not mock_send_mail.called
Esempio n. 2
0
def test_message(mock_send_mail):
    user = UserFactory(notify_by_message=True)
    notify.notify_users(notify.Notifications.ROLE_CHANGED, [user],
                        'Test subject', 'tests/test-message.html', {})
    # test that we send an message
    assert Message.objects.for_user(user).count() == 1
    last_message = Message.objects.for_user(user).order_by('-id')[:1].get()
    assert last_message.subject == 'Test subject'
Esempio n. 3
0
def test_send_email(mock_send_mail):
    """
    Templates often start with a line like "{% load i18n %}\n".  Make sure the
    newline at the end of that doesn't show up as a leading newline in the
    text message
    """

    user = UserFactory(notify_by_email=True)
    notify.notify_users(notify.Notifications.ROLE_CHANGED, [user],
                        'Test subject', 'tests/test-message.html', {})
Esempio n. 4
0
def send_invitation_message(invite):
    if not team_sends_notification(invite.team,'block_invitation_sent_message'):
        return False

    context = {
        'invite': invite,
        'role': invite.role,
        "user":invite.user,
        "inviter":invite.author,
        "team": invite.team,
        'note': invite.note,
        'custom_message': invite.team.get_message('messages_invite'),
    }
    title = fmt(_(u"You've been invited to the %(team)s team"),
                team=unicode(invite.team))

    notify_users(Notifications.TEAM_INVITATION, [invite.user], title,
                 'messages/team-invitation.html', context)
Esempio n. 5
0
def send_role_changed_message(member, old_member_info):
    team = member.team
    context = {
        'team': team,
        'member': member,
        'old_role_name': old_member_info.role_name,
        'new_role_name': member.get_role_name(),
        'team_name': unicode(team),
        'custom_message': team.get_message_for_role(member.role),
        'management_url': team.new_workflow.management_page_default(member.user),
        'was_a_project_or_language_manager': old_member_info.project_or_language_manager,
        'languages_managed': member.get_languages_managed(),
        'projects_managed': member.get_projects_managed(),
    }
    if was_promotion(member, old_member_info):
        subject = fmt(_('You have been promoted on the %(team)s team'),
                      team=unicode(team))
    else:
        subject = fmt(_('Your role has been changed on the %(team)s team'),
                      team=unicode(team))
    notify_users(Notifications.ROLE_CHANGED, [member.user], subject,
                 'messages/team-role-changed.html', context)
Esempio n. 6
0
def test_text_rendering(mock_send_mail):
    user = UserFactory(notify_by_email=True)
    notify.notify_users(notify.Notifications.ROLE_CHANGED, [user],
                        'Test subject', 'tests/test-message.html', {})
    text = mock_send_mail.call_args[0][1]
    assert text == """\
Esempio n. 7
0
def test_notify_by_message_unset(mock_send_mail):
    user = UserFactory(notify_by_message=False)
    notify.notify_users(notify.Notifications.ROLE_CHANGED, [user],
                        'Test subject', 'tests/test-message.html', {})
    # test that we don't send a message
    assert Message.objects.for_user(user).count() == 0