def test_users_select(self): try: database = Database() sql = 'SELECT * FROM Users' database.execute(sql).fetchall() except sqlite3.OperationalError: self.fail()
def test_select(self): database = Database() sql = 'SELECT "Hello World!"' rows = database.execute(sql).fetchall() self.assertEqual(len(rows), 1) self.assertEqual(len(rows[0]), 1) self.assertEqual(rows[0][0], 'Hello World!')
def test_create_user(self): try: database = Database() database.add_user('username', 'password') sql = 'SELECT COUNT(*) FROM Users WHERE Name="username"' row = database.execute(sql).fetchone() self.assertEqual(row[0], 1) except sqlite3.IntegrityError as e: self.assertEqual(str(e), 'UNIQUE constraint failed: Users.Name')
def test_users_if_exists(self): database = Database() sql = 'SELECT COUNT(name) FROM sqlite_master WHERE name="Users"' row = database.execute(sql).fetchone() self.assertEqual(row[0], 1)