Merge pull request #149 from dshulyak/ut_for_events_db
Ut for events db
This commit is contained in:
commit
6b48d25f84
@ -55,6 +55,7 @@ def add_dep(parent, dep, actions, state='success'):
|
||||
add_event(d)
|
||||
log.debug('Added event: %s', d)
|
||||
|
||||
|
||||
def add_react(parent, dep, actions, state='success'):
|
||||
for act in actions:
|
||||
r = React(parent, act, state=state,
|
||||
@ -62,13 +63,6 @@ def add_react(parent, dep, actions, state='success'):
|
||||
add_event(r)
|
||||
log.debug('Added event: %s', r)
|
||||
|
||||
def remove_event(ev):
|
||||
rst = all_events(ev.parent_node)
|
||||
db.create(
|
||||
ev.parent_node,
|
||||
[i.to_dict() for i in rst],
|
||||
collection=db.COLLECTIONS.events)
|
||||
|
||||
|
||||
def set_events(resource, lst):
|
||||
db.create(
|
||||
@ -77,6 +71,11 @@ def set_events(resource, lst):
|
||||
collection=db.COLLECTIONS.events)
|
||||
|
||||
|
||||
def remove_event(ev):
|
||||
rst = all_events(ev.parent_node)
|
||||
set_events(ev.parent_node, [it for it in rst if not it == ev])
|
||||
|
||||
|
||||
def add_events(resource, lst):
|
||||
rst = all_events(resource)
|
||||
rst.extend(lst)
|
||||
@ -88,7 +87,7 @@ def all_events(resource):
|
||||
return_empty=True, db_convert=False)
|
||||
if not events:
|
||||
return []
|
||||
return [create_event(i) for i in events['properties']]
|
||||
return [create_event(i) for i in events.properties]
|
||||
|
||||
|
||||
def bft_events_graph(start):
|
||||
|
@ -69,6 +69,9 @@ class Event(object):
|
||||
return '{}: {} -> {} -> {}'.format(
|
||||
self.etype, self.parent, self.state, self.dependent)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(repr(self))
|
||||
|
||||
|
||||
class Dependency(Event):
|
||||
|
||||
|
@ -31,8 +31,6 @@ def pytest_configure():
|
||||
def cleanup(request):
|
||||
|
||||
def fin():
|
||||
from solar.core import signals
|
||||
|
||||
db.get_db().clear()
|
||||
|
||||
request.addfinalizer(fin)
|
||||
|
@ -17,7 +17,6 @@ from dictdiffer import revert, patch
|
||||
import networkx as nx
|
||||
|
||||
from solar.system_log import change
|
||||
from solar.core.resource import wrap_resource
|
||||
|
||||
|
||||
@fixture
|
||||
|
@ -21,29 +21,40 @@ from solar.events import api as evapi
|
||||
from .base import BaseResourceTest
|
||||
|
||||
|
||||
class EventAPITest(BaseResourceTest):
|
||||
def test_events_load(self):
|
||||
sample_meta_dir = self.make_resource_meta("""
|
||||
id: sample
|
||||
handler: ansible
|
||||
version: 1.0.0
|
||||
input:
|
||||
value:
|
||||
schema: int
|
||||
value: 0
|
||||
""")
|
||||
@fixture
|
||||
def events_example():
|
||||
return [
|
||||
evapi.Dep('e1', 'run', 'success', 'e2', 'run'),
|
||||
evapi.Dep('e1', 'run', 'success', 'e3', 'run'),
|
||||
evapi.Dep('e1', 'run', 'success', 'e4', 'run'),
|
||||
]
|
||||
|
||||
sample1 = self.create_resource(
|
||||
'sample1', sample_meta_dir, {'value': 1}
|
||||
)
|
||||
|
||||
sample2 = self.create_resource(
|
||||
'sample2', sample_meta_dir, {'value': 1}
|
||||
)
|
||||
def test_add_events(events_example):
|
||||
evapi.add_events('e1', events_example)
|
||||
assert set(evapi.all_events('e1')) == set(events_example)
|
||||
|
||||
|
||||
def test_set_events(events_example):
|
||||
partial = events_example[:2]
|
||||
evapi.add_events('e1', events_example[:2])
|
||||
evapi.set_events('e1', events_example[2:])
|
||||
|
||||
assert evapi.all_events('e1') == events_example[2:]
|
||||
|
||||
|
||||
def test_remove_events(events_example):
|
||||
to_be_removed = events_example[2]
|
||||
evapi.add_events('e1', events_example)
|
||||
evapi.remove_event(to_be_removed)
|
||||
assert to_be_removed not in evapi.all_events('e1')
|
||||
|
||||
|
||||
def test_single_event(events_example):
|
||||
evapi.add_events('e1', events_example[:2])
|
||||
evapi.add_event(events_example[2])
|
||||
assert set(evapi.all_events('e1')) == set(events_example)
|
||||
|
||||
evapi.Dep('sample1', 'run', 'success', 'sample2', 'run'),
|
||||
loaded = evapi.all_events(sample1)
|
||||
|
||||
|
||||
@fixture
|
||||
def nova_deps():
|
||||
|
Loading…
x
Reference in New Issue
Block a user