Esempio n. 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)
Esempio n. 2
0
def test_template_in_action():
    ac = ATestTemplateUsingAction(data={"template_data": TEST_TEMPLATE_DATA})
    context = Context.from_variables(name=u"Sir Test")
    template = ac.get_template(context)
    test_template_render(template)
    japanese_render = ac.get_template_values(context, ("ja",))
    name = template.context.get("name")
    assert name.upper() in japanese_render["body"]
    ac = ATestUnilingualTemplateUsingAction(data={"template_data": TEST_UNI_TEMPLATE_DATA})
    assert name in ac.get_template_values(context)["subject"]
Esempio n. 3
0
def test_template_in_action():
    ac = TestTemplateUsingAction(data={"template_data": TEST_TEMPLATE_DATA})
    context = Context.from_variables(name=u"Sir Test")
    template = ac.get_template(context)
    test_template_render(template)
    japanese_render = ac.get_template_values(context, ("ja",))
    name = template.context.get("name")
    assert name.upper() in japanese_render["body"]
    ac = TestUnilingualTemplateUsingAction(data={"template_data": TEST_UNI_TEMPLATE_DATA})
    assert name in ac.get_template_values(context)["subject"]
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)
Esempio n. 5
0
def get_test_template():
    ctx = Context.from_variables(name=u"Sir Test")
    template = Template(ctx, TEST_TEMPLATE_DATA)
    return template
Esempio n. 6
0
def get_test_template():
    ctx = Context.from_variables(name=u"Sir Test")
    template = Template(ctx, TEST_TEMPLATE_DATA)
    return template