diff --git a/solar/solar/events/api.py b/solar/solar/events/api.py index 75a6952c..fbeabd4a 100644 --- a/solar/solar/events/api.py +++ b/solar/solar/events/api.py @@ -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): diff --git a/solar/solar/events/controls.py b/solar/solar/events/controls.py index 537bc5cb..1d00c9e2 100644 --- a/solar/solar/events/controls.py +++ b/solar/solar/events/controls.py @@ -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): diff --git a/solar/solar/test/test_events.py b/solar/solar/test/test_events.py index 48a4843d..84860b26 100644 --- a/solar/solar/test/test_events.py +++ b/solar/solar/test/test_events.py @@ -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])