def test_put(self): db = Db(DB_PATH) db.put(TEST_KEY, TEST_VAL) db_val = db.get(TEST_KEY) print("PUT: %s, GET: %s" % (TEST_ITEM, db_val)) self.assertTrue(db_val.__dict__ == TEST_VAL.__dict__, "Failed to 'put' TEST_ITEM %s " "into %s" % (TEST_ITEM, DB_NAME))
def test_append(self): db = Db(DB_PATH) db.put(TEST_KEY, TEST_VAL) db.append(TEST_KEY, TEST_VAL) db_val = db.get(TEST_KEY) print("APPEND: %s, GET: %s" % (TEST_ITEM, db_val)) self.assertTrue(map(lambda x: x.__class__, db_val) == map(lambda x: x.__class__, [TEST_VAL] * 2), "Failed to 'append' TEST_ITEM %s " "into %s" % (TEST_ITEM, DB_NAME))
def GET(self): """Research http://news.ycombinator.com/item?id=1781013 how hacker news voting works and emulate """ msg = None i = web.input(pid=None) db = Db('db/openjournal') if i.pid: ps = db.get('papers') if not session().logged: msg = JS("Must be logged in to vote") else: try: ps[int(i.pid)]['votes'] += 1 db.put('papers', ps) except IndexError: return "No such items exists to vote on" return render().index(ps, msg=msg)
def disable(cls, uid): db = Db('db/{}'.format(DBNAME)) tickets = db.get(cls.KEY) tickets[int(uid)].enabled = False return db.put(cls.KEY, tickets)