DB: delete alarm/action
This commit is contained in:
parent
1d911caa9c
commit
0902331ee4
2 changed files with 34 additions and 1 deletions
|
@ -67,6 +67,12 @@ class EventModel(object):
|
|||
def update_action(self, actionid, new_fields={}):
|
||||
return self.actions.update(new_fields, eids=[actionid])
|
||||
|
||||
def delete_alarm(self, alarmid):
|
||||
return self.alarms.remove(eids=[alarmid])
|
||||
|
||||
def delete_action(self, actionid):
|
||||
return self.actions.remove(eids=[actionid])
|
||||
|
||||
|
||||
class Monitor(ParentedLet):
|
||||
'''
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from __future__ import print_function
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
|
@ -41,3 +40,31 @@ def test_add_multiple_alarms(db):
|
|||
assert len(db.actions.all()) == 2
|
||||
assert len(tuple(db.get_actions_by_alarm(
|
||||
db.get_alarm_by_id(alarm_id)))) == 2
|
||||
|
||||
|
||||
def test_delete_alarm(db):
|
||||
assert len(db.get_all_alarms()) == 0
|
||||
alarm_id = db.add_event(dict(kind='frequency', interval=60*3, start=1),
|
||||
[dict(kind='mpd', paths=['foo.mp3'], howmany=1)])
|
||||
action_id = next(db.get_actions_by_alarm(db.get_alarm_by_id(alarm_id))).eid
|
||||
assert len(db.get_all_alarms()) == 1
|
||||
db.delete_alarm(alarm_id)
|
||||
assert len(db.get_all_alarms()) == 0 # alarm deleted
|
||||
assert db.get_action_by_id(action_id) is not None
|
||||
assert 'kind' in db.get_action_by_id(action_id) # action still there
|
||||
|
||||
|
||||
def test_delete_alarm_nonexisting(db):
|
||||
with pytest.raises(KeyError):
|
||||
db.delete_alarm(123)
|
||||
|
||||
|
||||
def test_delete_action(db):
|
||||
alarm_id = db.add_event(dict(kind='frequency', interval=60*3, start=1),
|
||||
[dict(kind='mpd', paths=['foo.mp3'], howmany=1)])
|
||||
alarm = db.get_alarm_by_id(alarm_id)
|
||||
assert len(tuple(db.get_actions_by_alarm(alarm))) == 1
|
||||
action = next(db.get_actions_by_alarm(alarm))
|
||||
action_id = action.eid
|
||||
db.delete_action(action_id)
|
||||
assert len(tuple(db.get_actions_by_alarm(alarm))) == 0
|
||||
|
|
Loading…
Reference in a new issue