def test_update_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB, TEST_TABLE, col1=123, col2='abc') db.update_record(TEST_DB, TEST_TABLE, 999, col2='def') res = db.get_record(TEST_DB, TEST_TABLE, id) self.assertEqual(res, {'rowid': id, 'col1': 123, 'col2': 'abc'}) db.update_record(TEST_DB, TEST_TABLE, id, col2='def') res = db.get_record(TEST_DB, TEST_TABLE, 1) self.assertEqual(res, {'rowid': id, 'col1': 123, 'col2': 'def'})
def test_update_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB,TEST_TABLE,col1=123,col2='abc') db.update_record(TEST_DB,TEST_TABLE,999,col2='def') res = db.get_record(TEST_DB,TEST_TABLE,id) self.assertEqual(res, {'rowid':id,'col1':123,'col2':'abc'}) db.update_record(TEST_DB,TEST_TABLE,id,col2='def') res = db.get_record(TEST_DB,TEST_TABLE,1) self.assertEqual(res, {'rowid':id,'col1':123,'col2':'def'})
def test_get_record(self): self.conn.execute(TEST_TABLESQL) res = db.get_record(TEST_DB,TEST_TABLE,1) self.assertEqual(res, None) num = randint(0,99) expected_result = {'rowid': 1, 'col1':num, 'col2':'TEST%d' % num} self.conn.execute("""INSERT INTO `%s` (ROWID,col1,col2) VALUES (1,?,?)""" % TEST_TABLE, (num, 'TEST%d' % num)) self.conn.commit() res = db.get_record(TEST_DB,TEST_TABLE,1) self.assertEqual(res, expected_result, '''get_record did not return expected result. expected: %s got: %s''' % (repr(expected_result), repr(res)))
def test_get_record(self): self.conn.execute(TEST_TABLESQL) res = db.get_record(TEST_DB, TEST_TABLE, 1) self.assertEqual(res, None) num = randint(0, 99) expected_result = {'rowid': 1, 'col1': num, 'col2': 'TEST%d' % num} self.conn.execute( """INSERT INTO `%s` (ROWID,col1,col2) VALUES (1,?,?)""" % TEST_TABLE, (num, 'TEST%d' % num)) self.conn.commit() res = db.get_record(TEST_DB, TEST_TABLE, 1) self.assertEqual( res, expected_result, '''get_record did not return expected result. expected: %s got: %s''' % (repr(expected_result), repr(res)))
def index(): users = db.get_all_users() users = list(map(list, users)) for user in users: uid = user[0] user.append(db.get_record(uid)) return render_template('index.html', users=users)
def get(self, database, table, rowid=None): """Dumps a single record or all records from a table""" try: if rowid: self.write(dumps(db.get_record(database, table, rowid))) else: self.write(dumps([row for row in db.all_records(database, table)])) except db.NoSuchDatabase: raise HTTPError(404)
def get(self, database, table, rowid=None): """Dumps a single record or all records from a table""" try: if rowid: self.write(dumps(db.get_record(database, table, rowid))) else: self.write( dumps([row for row in db.all_records(database, table)])) except db.NoSuchDatabase: raise HTTPError(404)
def test_delete_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB, TEST_TABLE, col1=123, col2='abc') db.delete_record(TEST_DB, TEST_TABLE, id) res = db.get_record(TEST_DB, TEST_TABLE, id) self.assertEqual(res, None)
def test_replace_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB, TEST_TABLE, col1=123, col2='abc') db.replace_record(TEST_DB, TEST_TABLE, id, [555, 'def']) res = db.get_record(TEST_DB, TEST_TABLE, id) self.assertEqual(res, {'rowid': id, 'col1': 555, 'col2': 'def'})
def test_insert_record(self): id = db.insert_record(TEST_DB, TEST_TABLE, col1=123, col2='abc') res = db.get_record(TEST_DB, TEST_TABLE, 1) self.assertNotEqual(id, None) self.assertEqual(res, {'rowid': id, 'col1': 123, 'col2': 'abc'})
def test_delete_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB,TEST_TABLE,col1=123,col2='abc') db.delete_record(TEST_DB,TEST_TABLE,id) res = db.get_record(TEST_DB,TEST_TABLE,id) self.assertEqual(res, None)
def test_replace_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB,TEST_TABLE,col1=123,col2='abc') db.replace_record(TEST_DB,TEST_TABLE,id,[555,'def']) res = db.get_record(TEST_DB,TEST_TABLE,id) self.assertEqual(res, {'rowid':id,'col1':555,'col2':'def'})
def test_insert_record(self): id = db.insert_record(TEST_DB,TEST_TABLE,col1=123,col2='abc') res = db.get_record(TEST_DB,TEST_TABLE,1) self.assertNotEqual(id, None) self.assertEqual(res, {'rowid':id,'col1':123,'col2':'abc'})