Verified Commit 41fa7c63 authored by Štěpán Henek's avatar Štěpán Henek 🐻
Browse files

update_settiongs: make hours_to_run not mandatory

parent 0f67cb9f
Pipeline #24969 passed with stage
in 3 minutes and 44 seconds
......@@ -58,12 +58,13 @@ class NetmetrUci():
"sync_code": sync_code,
}
def update_settings(self, autostart_enabled, hours_to_run):
def update_settings(self, autostart_enabled, hours_to_run=None):
with UciBackend() as backend:
backend.set_option(
"netmetr", "settings", "autostart_enabled", store_bool(autostart_enabled))
backend.replace_list("netmetr", "settings", "hours_to_run", hours_to_run)
if hours_to_run is not None:
backend.replace_list("netmetr", "settings", "hours_to_run", hours_to_run)
return True
......
......@@ -42,9 +42,10 @@ class MockNetmetrHandler(Handler, BaseMockHandler):
}
@logger_wrapper(logger)
def update_settings(self, autostart_enabled, hours_to_run):
self.hours_to_run = hours_to_run
def update_settings(self, autostart_enabled, hours_to_run=None):
self.autostart_enabled = autostart_enabled
if hours_to_run:
self.hours_to_run = hours_to_run
return True
@logger_wrapper(logger)
......
......@@ -39,7 +39,7 @@ class OpenwrtNetmetrHandler(Handler, BaseOpenwrtHandler):
return self.uci.get_settings()
@logger_wrapper(logger)
def update_settings(self, autostart_enabled, hours_to_run):
def update_settings(self, autostart_enabled, hours_to_run=None):
return self.uci.update_settings(autostart_enabled, hours_to_run)
@logger_wrapper(logger)
......
......@@ -48,7 +48,7 @@
}
},
"additionalProperties": false,
"required": ["autostart_enabled", "hours_to_run"]
"required": ["autostart_enabled"]
}
},
"additionalProperties": false,
......@@ -88,7 +88,7 @@
}
},
"additionalProperties": false,
"required": ["autostart_enabled", "hours_to_run"]
"required": ["autostart_enabled"]
}
},
"additionalProperties": false,
......
......@@ -68,6 +68,42 @@ def test_settings(infrastructure, ubusd_test):
},
}
# command without hours_to_run
new_autostart_enabled = not new_autostart_enabled
res = infrastructure.process_message({
"module": "netmetr",
"action": "update_settings",
"kind": "request",
"data": {
"autostart_enabled": new_autostart_enabled,
}
})
assert res["data"] == {"result": True}
notifications = infrastructure.get_notifications(notifications)
assert notifications[-1] == {
u"module": u"netmetr",
u"action": u"update_settings",
u"kind": u"notification",
u"data": {u"autostart_enabled": new_autostart_enabled},
}
res = infrastructure.process_message({
"module": "netmetr",
"action": "get_settings",
"kind": "request",
})
assert res == {
u"module": u"netmetr",
u"action": u"get_settings",
u"kind": u"reply",
u"data": {
u"sync_code": sync_code,
u"autostart_enabled": new_autostart_enabled,
u"hours_to_run": new_hours_to_run
},
}
def test_get_data(infrastructure, ubusd_test):
res = infrastructure.process_message({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment