Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
    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
Example #6
0
    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
Example #7
0
 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)