Beispiel #1
0
    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'})
Beispiel #2
0
    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'})
Beispiel #3
0
    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)))
Beispiel #4
0
    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)))
Beispiel #5
0
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)
Beispiel #6
0
 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)
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 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'})
Beispiel #10
0
 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'})
Beispiel #11
0
 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)
Beispiel #12
0
 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'})
Beispiel #13
0
 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'})