...
 
Commits (2)
......@@ -22,7 +22,7 @@ notifications:
template: simple_message
actions:
- dummy
version: 1
version: 1
- name: complex
template: complex_message
severity: error
......
......@@ -8,28 +8,104 @@ from notifylib.exceptions import (
NotificationNotDismissibleException,
)
# TODO: split fixtures and tests
@pytest.fixture
def volatile_dir(tmpdir):
return tmpdir.mkdir('volatile')
@pytest.fixture
def persistent_dir(tmpdir):
return tmpdir.mkdir('persistent')
@pytest.fixture
def plugin_dir(tmpdir):
return tmpdir.mkdir('plugins')
@pytest.fixture
def simple_plugin_dir(plugin_dir):
return plugin_dir.mkdir('simple')
@pytest.fixture
def tmp_dir(tmpdir):
return tmpdir.mkdir('notify')
def simple_plugin():
return """actions:
- name: reject
title: "{% trans %}Reject current update{% endtrans %}"
command: updater --reject-update
- name: dummy
title: "{% trans %}Dummy action{% endtrans %}"
command: /bin/true
templates:
- type: simple_message
supported_media:
- plain
- html
src: simple.j2
- type: complex_message
supported_media:
- plain
- html
- email
src: complex.j2
notifications:
- name: simple
template: simple_message
actions:
- dummy
version: 1
- name: complex
template: complex_message
severity: error
persistent: True
explicit_dismiss: False
actions:
- reject
version: 1
"""
@pytest.fixture
def volatile_dir(tmp_dir):
return tmp_dir.mkdir('volatile')
def template_simple():
return """{% if media == 'html' %}
<h3>{{ _("Simple message") }}</h3>
<p>
{{ _("HTML rendered message") }}: {{ message }}
</p>
{% else %}
= {{ _("Simple message") }} =
{{ _("Message") }}: {{message}}
{% endif %}"""
@pytest.fixture
def persistent_dir(tmp_dir):
return tmp_dir.mkdir('persistent')
def template_complex():
return """{% if media == 'html' %}
<h1>{{ _("Complex message") }}</h1>
<p>Lorem ipsum dolor sit amet</p>
<p>
{{ _("First message") }}: {{ message }}
<br>
{{ _("Second message") }}: {{ message2 }}
</p>
{% else %}
[{{ _("Complex message") }}]
{{ _("First message") }}: {{message}}
{{ _("Second message") }}: {{ message2 }}
{% endif %}"""
@pytest.fixture
def config(volatile_dir, persistent_dir):
def config(volatile_dir, persistent_dir, plugin_dir):
return {
'settings': {
'volatile_dir': volatile_dir,
'persistent_dir': persistent_dir,
'plugin_dir': plugin_dir,
}
}
......@@ -125,9 +201,43 @@ def dummy_notification():
"default_action": "dismiss"
}"""
def test_list_templates(config, simple_plugin_dir, simple_plugin, template_simple, template_complex):
plug = simple_plugin_dir.join('plugin.yml')
plug.write(simple_plugin)
tpl_dir = simple_plugin_dir.mkdir('templates')
tpl_simple = tpl_dir.join('simple.j2')
tpl_simple.write(template_simple)
tpl_complex = tpl_dir.join('complex.j2')
tpl_complex.write(template_complex)
api = Api(confdict=config)
templates = api.get_templates()
assert templates == ['simple.simple', 'simple.complex']
@pytest.mark.xfail
def test_create_notification(tmpdir, volatile_dir, config, dummy_notification):
def test_create_notification(
volatile_dir,
simple_plugin_dir,
config,
dummy_notification,
simple_plugin,
template_simple,
template_complex):
# TODO: figure out what to do with timestamp and notification id
plug = simple_plugin_dir.join('plugin.yml')
plug.write(simple_plugin)
tpl_dir = simple_plugin_dir.mkdir('templates')
tpl_simple = tpl_dir.join('simple.j2')
tpl_simple.write(template_simple)
tpl_complex = tpl_dir.join('complex.j2')
tpl_complex.write(template_complex)
api = Api(confdict=config)
opts = {
......@@ -145,11 +255,18 @@ def test_create_notification(tmpdir, volatile_dir, config, dummy_notification):
assert result == dummy_notification
def test_get_notification(volatile_dir, config, dummy_notification):
def test_get_notification(config, volatile_dir, simple_plugin_dir, simple_plugin, template_simple, dummy_notification):
"""Test notification lookup with full lenght id"""
f = volatile_dir.join('8c3ad32ca1774eed985604cc1a328773.json')
f.write(dummy_notification)
plug = simple_plugin_dir.join('plugin.yml')
plug.write(simple_plugin)
tpl_dir = simple_plugin_dir.mkdir('templates')
tpl_simple = tpl_dir.join('simple.j2')
tpl_simple.write(template_simple)
api = Api(confdict=config)
n = api.get_rendered_notification('8c3ad32ca1774eed985604cc1a328773')
......