def script_update(script_id): script_store = stores.get_store('scripts') rec = script_store.get(script_id) if rec is None: return _not_found_error("Script not found") script = Script(**rec[0]) script.update(request.json) script_store[script.id] = [script.to_dict(), clock.tick()] return dict(status=defines.SUCCESS, data=script_id)
def script_create(): script_store = stores.get_store('scripts') d = request.json if d.get('id') is not None: response.status = defines.HTTP_STATUS_BAD_REQUEST return dict(status=defines.ERROR, reason="Invalid data.") script = Script(**d) assert script.id is not None with script_store.cursor(readonly=False) as cur: cur.put(script.id, [script.to_dict(), clock.tick()]) return dict(status=defines.SUCCESS, data=script.id)
def test_can_save_and_load_notice(self, notice_store): notice = user.Notice(message='msg1', title='title1') rec = [notice.to_dict(), clock.tick()] notice_store[notice.id] = rec r2 = notice_store.get(notice.id) assert r2 is not None assert isinstance(r2, tuple) assert len(r2) == 2 d = r2[0] notice2 = user.Notice(**d) assert notice2.id == notice.id assert notice2.message == notice.message
def on_user_notified(self, notice): try: self._notice_store[notice.id] = [notice.to_dict(), clock.tick()] _logger.debug("User notice saved: %s", notice.id) except Exception: _logger.error("Failed to save notice to store.", exc_info=True)