def test_find_gt_ge_lt_le(self): mysql = self.new_db() table = "test_find_gt_ge_lt_le" count = 200 mysql.create_table(table, { "name": "varchar(255)", "age" : "int"}) users = [] for _ in range(count): name = random_str(5) age = random.randint(0, 100) user = {"name": name, "age": age} users.append(user) mysql.add_one(table, user) users_gt_50 = mysql.find_many(table, {"age": MySQLDB.gt(50)}) for user in users_gt_50: self.assertGreater(user["age"], 50) users_ge_50 = mysql.find_many(table, {"age": MySQLDB.ge(50)}) for user in users_ge_50: self.assertGreaterEqual(user["age"], 50) users_lt_50 = mysql.find_many(table, {"age": MySQLDB.lt(50)}) for user in users_lt_50: self.assertLess(user["age"], 50) users_le_50 = mysql.find_many(table, {"age": MySQLDB.le(50)}) for user in users_le_50: self.assertLessEqual(user["age"], 50) mysql.delete_table(table) mysql.close()
def test_insert_find_remove(self): mysql = self.new_db() table = "test_insert" mysql.create_table(table, { "name": "varchar(255)", "age" : "int"}) for _ in range(50): name = random_str(5) age = random.randint(0, 100) mysql.add_one(table, { "name": name, "age": age}) user = mysql.find_one(table, { "name": name}) self.assertEqual(user["name"], name) name = random_str(5) age = 20 mysql.add_one(table, { "name": name, "age": age}) users = mysql.find_many(table, {"age": age}) self.assertGreater(len(users), 0) least = 10 users = mysql.find_many(table, {"age": MySQLDB.gt(least)}) for user in users: self.assertGreater(user["age"], least) mysql.delete_table(table) mysql.close()
def get_priority_queue(self, maxsize=0): mysql = MySQLDB() mysql.connect(passwd="") mysql.select_db(TEST_DB) q = BigPriorityQueue(mysql, maxsize=maxsize) q.clear() return q
def test_connect_twice(self): mysql = MySQLDB() mysql.connect() with self.assertRaises(DatabaseError): mysql.connect() mysql.close()
def new_db(self): mysql = MySQLDB() mysql.connect(passwd="") mysql.select_db(TEST_DB) return mysql
def get_bd(self): mysql = MySQLDB() mysql.connect(passwd="") mysql.select_db(TEST_DB) return BigDict(mysql)