From fd2b0a4e55a903c289c55f7e49f1214e68f04ac2 Mon Sep 17 00:00:00 2001 From: s3lph Date: Tue, 28 Aug 2018 22:35:52 +0200 Subject: [PATCH] Better test coverage in database wrapper. --- matemat/db/test/test_wrapper.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/matemat/db/test/test_wrapper.py b/matemat/db/test/test_wrapper.py index 1b38f60..0b78890 100644 --- a/matemat/db/test/test_wrapper.py +++ b/matemat/db/test/test_wrapper.py @@ -103,3 +103,20 @@ class DatabaseTest(unittest.TestCase): with db.transaction(): with self.assertRaises(RuntimeError): self.db.close() + + def test_use_before_open(self): + with self.assertRaises(RuntimeError): + with self.db.transaction(): + pass + with self.assertRaises(RuntimeError): + self.db.close() + with self.assertRaises(RuntimeError): + _ = self.db._user_version + with self.assertRaises(RuntimeError): + self.db._user_version = 42 + + def test_setup_prevent_downgrade(self): + self.db._sqlite_db = sqlite3.connect(':memory:') + self.db._user_version = 1337 + with self.assertRaises(RuntimeError): + self.db._setup()