Merge pull request #331 from pigmej/new_db_events_tests
New db events tests
This commit is contained in:
commit
7fa43cc6bc
@ -83,7 +83,14 @@ def add_events(resource, lst):
|
||||
|
||||
|
||||
def remove_event(ev):
|
||||
raise NotImplemented()
|
||||
to_remove = ev.to_dict()
|
||||
resource = ev.parent
|
||||
resource = Resource.get(resource)
|
||||
# TODO: currently we don't track mutable objects
|
||||
events = resource.events
|
||||
events.remove(to_remove)
|
||||
resource.events = events
|
||||
resource.save_lazy()
|
||||
|
||||
|
||||
def all_events(resource):
|
||||
|
@ -32,6 +32,7 @@ trigger action even if no changes noticed on dependent resource.
|
||||
"""
|
||||
|
||||
from solar.dblayer.solar_models import Resource
|
||||
from solar.dblayer.model import DBLayerNotFound
|
||||
|
||||
class Event(object):
|
||||
|
||||
@ -97,7 +98,10 @@ class React(Event):
|
||||
|
||||
if self.parent_node in changes_graph:
|
||||
if self.child_node not in changes_graph:
|
||||
location_id = Resource.get(self.child).inputs['location_id']
|
||||
try:
|
||||
location_id = Resource.get(self.child).inputs['location_id']
|
||||
except DBLayerNotFound:
|
||||
location_id = None
|
||||
changes_graph.add_node(
|
||||
self.child_node, status='PENDING',
|
||||
target=location_id,
|
||||
@ -106,7 +110,7 @@ class React(Event):
|
||||
|
||||
changes_graph.add_edge(
|
||||
self.parent_node, self.child_node, state=self.state)
|
||||
changed_resources.append(self.child)
|
||||
changed_resources.append(self.child_node)
|
||||
|
||||
|
||||
class StateChange(Event):
|
||||
|
@ -17,7 +17,7 @@ import networkx as nx
|
||||
from pytest import fixture
|
||||
|
||||
from solar.events import api as evapi
|
||||
from solar.interfaces import orm
|
||||
from solar.dblayer.solar_models import Resource
|
||||
|
||||
from .base import BaseResourceTest
|
||||
|
||||
@ -32,24 +32,15 @@ def events_example():
|
||||
|
||||
|
||||
def test_add_events(events_example):
|
||||
r = orm.DBResource(id='e1', name='e1', base_path='x')
|
||||
r = Resource.from_dict(dict(key='e1', name='e1', base_path='x'))
|
||||
r.save()
|
||||
|
||||
evapi.add_events('e1', events_example)
|
||||
assert set(evapi.all_events('e1')) == set(events_example)
|
||||
|
||||
|
||||
def test_set_events(events_example):
|
||||
r = orm.DBResource(id='e1', name='e1', base_path='x')
|
||||
r.save()
|
||||
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):
|
||||
r = orm.DBResource(id='e1', name='e1', base_path='x')
|
||||
r = Resource.from_dict(dict(key='e1', name='e1', base_path='x'))
|
||||
r.save()
|
||||
to_be_removed = events_example[2]
|
||||
evapi.add_events('e1', events_example)
|
||||
@ -58,7 +49,7 @@ def test_remove_events(events_example):
|
||||
|
||||
|
||||
def test_single_event(events_example):
|
||||
r = orm.DBResource(id='e1', name='e1', base_path='x')
|
||||
r = Resource.from_dict(dict(key='e1', name='e1', base_path='x'))
|
||||
r.save()
|
||||
evapi.add_events('e1', events_example[:2])
|
||||
evapi.add_event(events_example[2])
|
||||
|
Loading…
Reference in New Issue
Block a user