1
0
Fork 0
forked from s3lph/matemat

Added additional unit tests.

This commit is contained in:
s3lph 2018-07-14 23:44:27 +02:00
parent 5c9d85fa70
commit 69601150a7

View file

@ -75,3 +75,29 @@ class DatabaseTest(unittest.TestCase):
c = db._sqlite_db.cursor()
c.execute("SELECT * FROM users")
self.assertIsNone(c.fetchone())
def test_connect_twice(self):
"""
If a connection is already established, a RuntimeError should be raised when attempting to connect a
second time.
"""
self.db.connect()
with self.assertRaises(RuntimeError):
self.db.connect()
self.db.close()
def test_close_not_opened(self):
"""
Attempting to close an unopened connection should raise a RuntimeError.
"""
with self.assertRaises(RuntimeError):
self.db.close()
def test_close_in_transaction(self):
"""
Attempting to close a connection inside a transaction should raise a RuntimeError.
"""
with self.db as db:
with db.transaction():
with self.assertRaises(RuntimeError):
self.db.close()