def test_all_records(self): self.conn.execute(TEST_TABLESQL) res = [rec for rec in db.all_records(TEST_DB,TEST_TABLE)] self.assertEqual(res, [], 'all_records should return an empty set at this stage') expected_set = [] for i in range(10): num = randint(0,99) expected_set.append({'rowid':num, 'col1':num, 'col2':'TEST%d' % num}) self.conn.execute("""INSERT INTO `%s` VALUES (?,?)""" % TEST_TABLE, (num, 'TEST%d' % num)) for record in db.all_records(TEST_DB, TEST_TABLE): self.assert_(record in expected_set)
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_all_records(self): self.conn.execute(TEST_TABLESQL) res = [rec for rec in db.all_records(TEST_DB, TEST_TABLE)] self.assertEqual( res, [], 'all_records should return an empty set at this stage') expected_set = [] for i in range(10): num = randint(0, 99) expected_set.append({ 'rowid': num, 'col1': num, 'col2': 'TEST%d' % num }) self.conn.execute("""INSERT INTO `%s` VALUES (?,?)""" % TEST_TABLE, (num, 'TEST%d' % num)) for record in db.all_records(TEST_DB, TEST_TABLE): self.assert_(record in expected_set)
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)