Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqltests #25

Merged
merged 11 commits into from
May 27, 2017
34 changes: 8 additions & 26 deletions tests/sqltests.py
Original file line number Diff line number Diff line change
@@ -72,14 +72,6 @@ def test_update_returns_affected_rows(self):
self.assertEqual(self.db.execute("UPDATE cs50 SET val = 'foo' WHERE id > 1"), 2)
self.assertEqual(self.db.execute("UPDATE cs50 SET val = 'foo' WHERE id = -50"), 0)

class MySQLTests(SQLTests):
@classmethod
def setUpClass(self):
self.db = SQL("mysql://root@localhost/test")

def setUp(self):
self.db.execute("CREATE TABLE cs50 (id INTEGER NOT NULL AUTO_INCREMENT, val VARCHAR(16), PRIMARY KEY (id))")

def tearDown(self):
self.db.execute("DROP TABLE cs50")

@@ -92,24 +84,21 @@ def tearDownClass(self):
if not str(e).startswith("(1051"):
raise e

class PostgresTests(SQLTests):
class MySQLTests(SQLTests):
@classmethod
def setUpClass(self):
self.db = SQL("postgresql://postgres@localhost/test")
self.db = SQL("mysql://root@localhost/test")

def setUp(self):
self.db.execute("CREATE TABLE cs50 (id SERIAL PRIMARY KEY, val VARCHAR(16))")

def tearDown(self):
self.db.execute("DROP TABLE cs50")
self.db.execute("CREATE TABLE cs50 (id INTEGER NOT NULL AUTO_INCREMENT, val VARCHAR(16), PRIMARY KEY (id))")

class PostgresTests(SQLTests):
@classmethod
def tearDownClass(self):
self.db.execute("DROP TABLE IF EXISTS cs50")
def setUpClass(self):
self.db = SQL("postgresql://postgres@localhost/test")

def test_insert_returns_last_row_id(self):
self.assertEqual(self.db.execute("INSERT INTO cs50(val) VALUES('foo')"), 1)
self.assertEqual(self.db.execute("INSERT INTO cs50(val) VALUES('bar')"), 2)
def setUp(self):
self.db.execute("CREATE TABLE cs50 (id SERIAL PRIMARY KEY, val VARCHAR(16))")

class SQLiteTests(SQLTests):
@classmethod
@@ -119,13 +108,6 @@ def setUpClass(self):
def setUp(self):
self.db.execute("CREATE TABLE cs50(id INTEGER PRIMARY KEY, val TEXT)")

def tearDown(self):
self.db.execute("DROP TABLE cs50")

@classmethod
def tearDownClass(self):
self.db.execute("DROP TABLE IF EXISTS cs50")

if __name__ == "__main__":
suite = unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(SQLiteTests),