def set_events(resource, lst): resource_events = orm.DBResourceEvents.get_or_create(resource) for ev in resource_events.events.as_set(): ev.delete() for ev in lst: event_db = orm.DBEvent(**ev.to_dict()) event_db.save() resource_events.events.add(event_db)
def test_save_several(self): ev = orm.DBEvent( parent='n1', parent_action='run', state='success', child_action='run', child='n2', etype='dependency') ev.save() ev1 = orm.DBEvent( parent='n1', parent_action='run', state='success', child_action='run', child='n3', etype='dependency') ev1.save() self.assertEqual(len(orm.DBEvent.load_all()), 2)
def add_event(ev): rst = all_events(ev.parent) for rev in rst: if ev == rev: break else: rst.append(ev) resource_events = orm.DBResourceEvents.get_or_create(ev.parent) event_db = orm.DBEvent(**ev.to_dict()) event_db.save() resource_events.events.add(event_db)
def test_save_and_load_by_parent(self): ev = orm.DBEvent( parent='n1', parent_action='run', state='success', child_action='run', child='n2', etype='dependency') ev.save() rst = orm.DBEvent.load(ev.id) self.assertEqual(rst, ev)
def test_removal_of_event(self): r = orm.DBResourceEvents(id='test1') r.save() ev = orm.DBEvent( parent='test1', parent_action='run', state='success', child_action='run', child='n2', etype='dependency') ev.save() r.events.add(ev) self.assertEqual(r.events.as_set(), {ev}) ev.delete() r = orm.DBResourceEvents.load('test1') self.assertEqual(r.events.as_set(), set())
def remove_event(ev): event_db = orm.DBEvent(**ev.to_dict()) event_db.delete()