Skip to content

Commit

Permalink
Add jinja event plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rnv812 committed Jul 3, 2024
1 parent 3ca3b8f commit efbb521
Showing 1 changed file with 124 additions and 15 deletions.
139 changes: 124 additions & 15 deletions eventum_plugins/event/tests/test_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def test_rendering():
params={},
samples={},
mode=TemplatePickingMode.ALL,
templates=[{
'test': TemplateConfig(template='test.jinja')
}]
templates=[{'test': TemplateConfig(template='test.jinja')}]
),
loader=DictLoader(mapping={'test.jinja': '1 + 1 = {{ 1 + 1 }}'})
).render()
Expand All @@ -36,9 +34,7 @@ def test_rendering_parameters():
params={'passed_parameter': 'value of parameter'},
samples={},
mode=TemplatePickingMode.ALL,
templates=[{
'test': TemplateConfig(template='test.jinja')
}]
templates=[{'test': TemplateConfig(template='test.jinja')}]
),
loader=DictLoader(mapping={'test.jinja': '{{ test_param }}'})
).render(test_param='test value')
Expand All @@ -58,9 +54,7 @@ def test_items_sample():
)
},
mode=TemplatePickingMode.ALL,
templates=[{
'test': TemplateConfig(template='test.jinja')
}]
templates=[{'test': TemplateConfig(template='test.jinja')}]
),
loader=DictLoader(
mapping={'test.jinja': '{{ samples.test_sample[0] }}'}
Expand All @@ -82,9 +76,7 @@ def test_csv_sample():
)
},
mode=TemplatePickingMode.ALL,
templates=[{
'test': TemplateConfig(template='test.jinja')
}]
templates=[{'test': TemplateConfig(template='test.jinja')}]
),
loader=DictLoader(
mapping={'test.jinja': '{{ samples.test_sample[0] }}'}
Expand All @@ -101,9 +93,7 @@ def test_subprocess():
params={},
samples={},
mode=TemplatePickingMode.ALL,
templates=[{
'test': TemplateConfig(template='test.jinja')
}]
templates=[{'test': TemplateConfig(template='test.jinja')}]
),
loader=DictLoader(
mapping={
Expand All @@ -116,3 +106,122 @@ def test_subprocess():

assert len(events) == 1
assert events.pop() == 'Hello, World!'


def test_templates_picking_all():
events = JinjaEventPlugin(
config=JinjaEventConfig(
params={},
samples={},
mode=TemplatePickingMode.ALL,
templates=[
{'a': TemplateConfig(template='a.jinja')},
{'b': TemplateConfig(template='b.jinja')},
{'c': TemplateConfig(template='c.jinja')}
]
),
loader=DictLoader(
mapping={
'a.jinja': 'a',
'b.jinja': 'b',
'c.jinja': 'c'
}
)
).render()

assert events == ['a', 'b', 'c']


def test_templates_picking_any():
plugin = JinjaEventPlugin(
config=JinjaEventConfig(
params={},
samples={},
mode=TemplatePickingMode.ANY,
templates=[
{'a': TemplateConfig(template='a.jinja')},
{'b': TemplateConfig(template='b.jinja')},
{'c': TemplateConfig(template='c.jinja')}
]
),
loader=DictLoader(
mapping={
'a.jinja': 'a',
'b.jinja': 'b',
'c.jinja': 'c'
}
)
)

events = plugin.render()
assert len(events) == 1

events = []
for _ in range(100):
events.extend(plugin.render())

for event in ['a', 'b', 'c']:
assert event in events


def test_templates_picking_spin():
plugin = JinjaEventPlugin(
config=JinjaEventConfig(
params={},
samples={},
mode=TemplatePickingMode.SPIN,
templates=[
{'a': TemplateConfig(template='a.jinja')},
{'b': TemplateConfig(template='b.jinja')},
{'c': TemplateConfig(template='c.jinja')}
]
),
loader=DictLoader(
mapping={
'a.jinja': 'a',
'b.jinja': 'b',
'c.jinja': 'c'
}
)
)

events = plugin.render()
assert len(events) == 1
assert 'a' in events

events = plugin.render()
assert len(events) == 1
assert 'b' in events

events = plugin.render()
assert len(events) == 1
assert 'c' in events

events = plugin.render()
assert len(events) == 1
assert 'a' in events


def test_templates_picking_chance():
events = JinjaEventPlugin(
config=JinjaEventConfig(
params={},
samples={},
mode=TemplatePickingMode.CHANCE,
templates=[
{'a': TemplateConfig(template='a.jinja', chance=0.000001)},
{'b': TemplateConfig(template='b.jinja', chance=999999)},
{'c': TemplateConfig(template='c.jinja', chance=0.000001)}
]
),
loader=DictLoader(
mapping={
'a.jinja': 'a',
'b.jinja': 'b',
'c.jinja': 'c'
}
)
).render()

assert len(events) == 1
assert 'b' in events

0 comments on commit efbb521

Please sign in to comment.