Пример #1
0
def test_notification(admin_user, specific_user):
    AddNotification(make_bind_data(
        variables={"priority": "priority"},
        constants={
            "message": "Hi {{ name }}!",
            "message_identifier": "hi mom",
            "url": "http://burymewithmymoney.com/",
            "recipient_type": (RecipientType.SPECIFIC_USER if specific_user else RecipientType.ADMINS),
            "recipient": (admin_user if specific_user else None),
            "priority": Priority.CRITICAL
        }
    )).execute(Context.from_variables(name="Justin Case"))
    notif = Notification.objects.last()
    assert isinstance(notif, Notification)
    if specific_user:
        assert notif.recipient == admin_user
        assert Notification.objects.unread_for_user(admin_user).get(pk=notif.pk)
    assert notif.identifier == "hi mom"
    assert notif.message == "Hi Justin Case!"
    assert notif.priority == Priority.CRITICAL
    assert notif.url == "http://burymewithmymoney.com/"
    with pytest.raises(ValueError):
        notif.url = "http://www.theuselessweb.com/"

    assert not notif.is_read
    notif.mark_read(admin_user)  # Once, for setting
    notif.mark_read(admin_user)  # Twice, for branch checking
    assert notif.marked_read_by == admin_user
    assert very_recently(notif.marked_read_on)
Пример #2
0
def test_misconfigured_add_notification_is_noop():
    n_notifs = Notification.objects.count()
    AddNotification(make_bind_data(
        constants={
            "recipient_type": RecipientType.SPECIFIC_USER,
            "message": "This'll never get delivered!",
        }
    )).execute(Context())
    assert Notification.objects.count() == n_notifs
def test_misconfigured_add_notification_is_noop():
    n_notifs = Notification.objects.count()
    AddNotification(
        make_bind_data(
            constants={
                "recipient_type": RecipientType.SPECIFIC_USER,
                "message": "This'll never get delivered!",
            })).execute(Context())
    assert Notification.objects.count() == n_notifs
def test_notification(admin_user, specific_user):
    AddNotification(
        make_bind_data(variables={"priority": "priority"},
                       constants={
                           "message":
                           "Hi {{ name }}!",
                           "message_identifier":
                           "hi mom",
                           "url":
                           "http://burymewithmymoney.com/",
                           "recipient_type":
                           (RecipientType.SPECIFIC_USER
                            if specific_user else RecipientType.ADMINS),
                           "recipient":
                           (admin_user if specific_user else None),
                           "priority":
                           Priority.CRITICAL
                       })).execute(Context.from_variables(name="Justin Case"))
    notif = Notification.objects.last()
    assert isinstance(notif, Notification)
    if specific_user:
        assert notif.recipient == admin_user
        assert Notification.objects.unread_for_user(admin_user).get(
            pk=notif.pk)
    assert notif.identifier == "hi mom"
    assert notif.message == "Hi Justin Case!"
    assert notif.priority == Priority.CRITICAL
    assert notif.url == "http://burymewithmymoney.com/"
    with pytest.raises(ValueError):
        notif.url = "http://www.theuselessweb.com/"

    assert not notif.is_read
    notif.mark_read(admin_user)  # Once, for setting
    notif.mark_read(admin_user)  # Twice, for branch checking
    assert notif.marked_read_by == admin_user
    assert very_recently(notif.marked_read_on)