Added additional unit tests.
This commit is contained in:
parent
5c9d85fa70
commit
69601150a7
1 changed files with 26 additions and 0 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue