def test_updatepassword2(self): a = User(username="******", password="******", name="ray", detail="") b = User(username="******", password="******", name="ray", detail="") s = [a, b] user_db.insert_users_table(s) self.assertTrue( user_db.update_user_password(1, "ssssdskkkdjjdnvnkskd11s"))
def test_selectpassword2(self): a = User(username="******", password="******", name="ray", detail="") b = User(username="******", password="******", name="ray", detail="") s = [a, b] user_db.insert_users_table(s) self.assertEqual(user_db.select_password("2ry", "ssss"), None) self.assertEqual(user_db.select_password("1ra", "ssss"), None)
def test_update2(self): a = User(username="******", password="******", name="ray", detail="") b = User(username="******", password="******", name="ray", detail="") s = [a, b] user_db.insert_users_table(s) c = User(username="******", password="******", name="rdsday", detail="13132") self.assertTrue(user_db.update_user_table(9, c))
def test_user(self): a = User(username="******", password="******", name="ray", detail="") b = User(username="******", password="******", name="ray", detail="") s = [a, b] c = User(username="******", password="******", name="ray", detail="1);DROP TABLE if exists USER--") self.assertTrue(user_db.insert_users_table(s)) self.assertTrue(user_db.insert_user_table(c)) user_db.drop_user_table() user_db.init_user_table() s.append(c) self.assertTrue(user_db.insert_users_table(s)) self.assertFalse( user_db.delete_user_table2("1);DROP TABLE if exists USER--")) self.assertTrue(user_db.update_user_table(1, c)) self.assertEqual( user_db.select_user_name("1ray);DROP TABLE if exists USER--"), None) self.assertEqual( user_db.select_password("1ray", "sss);DROP TABLE if exists USER--"), None) self.assertEqual( user_db.select_user("1ray", "sss);DROP TABLE if exists USER--"), None)
def test_insertmany3(self): a = User(username="******", password="******", name="ray", detail="") b = User(username="******", password="******", name="ray", detail="") s = [a, b] self.assertTrue(user_db.insert_users_table(s))
def test_updatepassword3(self): a = User(username="******", password="******", name="ray", detail="") b = User(username="******", password="******", name="ray", detail="") s = [a, b] user_db.insert_users_table(s) self.assertFalse(user_db.update_user_password(None, "ss")) self.assertFalse(user_db.update_user_password(1, None)) self.assertFalse(user_db.update_user_password(None, None))
def test_update3(self): a = User(username="******", password="******", name="ray", detail="") b = User(username="******", password="******", name="ray", detail="") s = [a, b] user_db.insert_users_table(s) c = User(username="******", password="******", name="rdsday", detail="13132") self.assertFalse(user_db.update_user_table(None, None)) self.assertFalse(user_db.update_user_table(1, None)) self.assertFalse(user_db.update_user_table(None, c))
def select_user(username, password): if username == None or password == None: return None sql = "SELECT * FROM USER WHERE user_name=%s AND password=%s;" conn = set_conect() cursor = conn.cursor() try: cursor.execute(sql, (username, password)) conn.commit() result = cursor.fetchone() user = User(username=result[1], password=result[2], detail=result[3], name=result[4]) except: print("select_password error") return None finally: cursor.close() conn.close() return user
def test_deleteid2(self): a = User(username="******", password="******", name="ray", detail="") b = User(username="******", password="******", name="ray", detail="") s = [a, b] user_db.insert_users_table(s) self.assertTrue(user_db.delete_user_table2(10))
def test_insert2(self): a = User(username="******", password="******", name="ray", detail="") self.assertFalse(user_db.insert_user_table(a))
def test_selectuser1(self): a = User(username="******", password="******", name="ray", detail="") b = User(username="******", password="******", name="ray", detail="") s = [a, b] user_db.insert_users_table(s) self.assertEqual(user_db.select_user("1ray", "sss").username, "1ray")
def test_insert1(self): a = User(username="******", password="******", name="ray", detail="") self.assertTrue(user_db.insert_user_table(a))
def test_insertmany6(self): a = User(username="******", password="******", name="ray", detail="") b = None s = [a, b] self.assertFalse(user_db.insert_users_table(s))
def inituser(): user_db.drop_user_table() user_db.init_user_table() user_db.insert_user_table( User(username="******", password="******", name="ray", detail=""))