From 69601150a79833ad6abddb4919bbb6ce553139b8 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 14 Jul 2018 23:44:27 +0200 Subject: [PATCH] Added additional unit tests. --- matemat/db/test/test_wrapper.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/matemat/db/test/test_wrapper.py b/matemat/db/test/test_wrapper.py index dafff65..e5a52c2 100644 --- a/matemat/db/test/test_wrapper.py +++ b/matemat/db/test/test_wrapper.py @@ -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()