From 5ad748c4cb54c9a53b0277e09d52b098d816bea8 Mon Sep 17 00:00:00 2001 From: piotras Date: Mon, 11 Feb 2013 10:40:07 +0100 Subject: [PATCH] Execute all SQL operations inside transaction. Refs gh-185 --- tests/GIR/test_020_connection.py | 12 +++++++++++- tests/GIR/test_100_object_crud.py | 2 ++ tests/GIR/test_110_object_metadata.py | 2 ++ tests/GIR/test_120_object_attachments.py | 2 ++ tests/GIR/test_130_object_tree.py | 5 ++--- tests/GIR/test_200_user.py | 2 ++ tests/GIR/test_220_blob.py | 2 ++ tests/GIR/test_400_workspace_manager.py | 2 ++ tests/GIR/test_401_workspace.py | 2 ++ tests/GIR/test_402_workspace_context.py | 2 ++ tests/GIR/test_411_object_in_workspace.py | 3 +++ tests/GIR/test_412_object_in_workspace_context.py | 7 +++++-- tests/GIR/test_930_execution_pool.py | 2 ++ tests/GIR/test_940_content_manager.py | 2 ++ tests/GIR/test_950_content_manager_job_create.py | 2 ++ tests/GIR/test_951_content_manager_job_update.py | 2 ++ tests/GIR/test_952_content_manager_job_delete.py | 2 ++ tests/GIR/test_953_content_manager_job_purge.py | 2 ++ tests/GIR/test_954_content_manager_job_load.py | 2 ++ 19 files changed, 51 insertions(+), 6 deletions(-) diff --git a/tests/GIR/test_020_connection.py b/tests/GIR/test_020_connection.py index 4995d75f..39f4085c 100644 --- a/tests/GIR/test_020_connection.py +++ b/tests/GIR/test_020_connection.py @@ -8,6 +8,9 @@ from gi.repository import Midgard, GObject class TestConnection(Midgard.Connection): + + transaction = None + def __init__(self): Midgard.init() Midgard.Connection.__init__(self) @@ -15,12 +18,19 @@ def __init__(self): @staticmethod def openConnection(): config = TestConfig() - mgd = Midgard.Connection() + mgd = TestConnection() if mgd.open_config(config) is True: return mgd print mgd.get_error_string() return None + def beginTransaction(self): + self.transaction = Midgard.Transaction(connection = self) + self.transaction.begin() + + def commitTransaction(self): + self.transaction.commit() + class TestMethods(unittest.TestCase): def testOpenConfig(self): config = TestConfig() diff --git a/tests/GIR/test_100_object_crud.py b/tests/GIR/test_100_object_crud.py index 9d6a77aa..10c6b2a1 100644 --- a/tests/GIR/test_100_object_crud.py +++ b/tests/GIR/test_100_object_crud.py @@ -16,6 +16,7 @@ class TestObjectCrud(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.bookstore is None: self.bookstore = Midgard.Object.factory(self.mgd, "gir_test_book_store", None) self.bookstore.set_property("name", "BookStore") @@ -24,6 +25,7 @@ def setUp(self): def tearDown(self): if self.bookstore is not None: self.bookstore.purge(False) + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_110_object_metadata.py b/tests/GIR/test_110_object_metadata.py index 0a1b2483..51e5258a 100644 --- a/tests/GIR/test_110_object_metadata.py +++ b/tests/GIR/test_110_object_metadata.py @@ -16,6 +16,7 @@ class TestObjectMetadataCrud(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.bookstore is None: self.bookstore = Midgard.Object.factory(self.mgd, "gir_test_book_store", None) self.bookstore.set_property("name", "BookStore") @@ -24,6 +25,7 @@ def setUp(self): def tearDown(self): if self.bookstore is not None: self.bookstore.purge(False) + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_120_object_attachments.py b/tests/GIR/test_120_object_attachments.py index 048c83ac..59686442 100644 --- a/tests/GIR/test_120_object_attachments.py +++ b/tests/GIR/test_120_object_attachments.py @@ -16,6 +16,7 @@ class TestAttachment(unittest.TestCase): def setUp(self): if self.mgd is None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.bookstore is None: self.bookstore = Midgard.Object.factory(self.mgd, "gir_test_book_store", None) self.bookstore.set_property("name", "BookStore") @@ -29,6 +30,7 @@ def setUp(self): def tearDown(self): if self.bookstore is not None: self.bookstore.purge(False) + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_130_object_tree.py b/tests/GIR/test_130_object_tree.py index 031f4983..ba1242a8 100644 --- a/tests/GIR/test_130_object_tree.py +++ b/tests/GIR/test_130_object_tree.py @@ -15,10 +15,9 @@ class TestSchemaObjectTree(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() def purgeSnippets(self): - tr = Midgard.Transaction(connection = self.mgd) - tr.begin() st = Midgard.QueryStorage(dbclass = "midgard_snippet") qs = Midgard.QuerySelect(connection = self.mgd, storage = st) qs.execute() @@ -29,10 +28,10 @@ def purgeSnippets(self): qs.execute() for s in qs.list_objects(): s.purge(False) - tr.commit() def tearDown(self): self.purgeSnippets() + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_200_user.py b/tests/GIR/test_200_user.py index e13bac3d..00daf5b6 100644 --- a/tests/GIR/test_200_user.py +++ b/tests/GIR/test_200_user.py @@ -15,8 +15,10 @@ class TestUser(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() def tearDown(self): + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_220_blob.py b/tests/GIR/test_220_blob.py index df9ca465..9a5ee690 100644 --- a/tests/GIR/test_220_blob.py +++ b/tests/GIR/test_220_blob.py @@ -15,6 +15,7 @@ class TestBlob(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() self.attachment = Midgard.Object.factory(self.mgd, "midgard_attachment", None) self.attachment.set_property("title", "TestTitle") self.attachment.set_property("name", "TestName") @@ -26,6 +27,7 @@ def tearDown(self): if self.blob.exists(): self.blob.remove_file() self.attachment.purge(False) + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_400_workspace_manager.py b/tests/GIR/test_400_workspace_manager.py index 1dfbd394..a220da1d 100644 --- a/tests/GIR/test_400_workspace_manager.py +++ b/tests/GIR/test_400_workspace_manager.py @@ -16,10 +16,12 @@ class TestWorkspaceManager(unittest.TestCase): def setUp(self): if self.mgd is None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.manager is None: self.manager = Midgard.WorkspaceManager(connection = self.mgd) def tearDown(self): + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_401_workspace.py b/tests/GIR/test_401_workspace.py index 3b0333b1..5f3c28de 100644 --- a/tests/GIR/test_401_workspace.py +++ b/tests/GIR/test_401_workspace.py @@ -16,10 +16,12 @@ class TestWorkspace(unittest.TestCase): def setUp(self): if self.mgd is None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.manager is None: self.manager = Midgard.WorkspaceManager(connection = self.mgd) def tearDown(self): + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_402_workspace_context.py b/tests/GIR/test_402_workspace_context.py index 6286c0ec..6f9921a0 100644 --- a/tests/GIR/test_402_workspace_context.py +++ b/tests/GIR/test_402_workspace_context.py @@ -16,10 +16,12 @@ class TestWorkspaceContext(unittest.TestCase): def setUp(self): if self.mgd is None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.manager is None: self.manager = Midgard.WorkspaceManager(connection = self.mgd) def tearDown(self): + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_411_object_in_workspace.py b/tests/GIR/test_411_object_in_workspace.py index b7abf0d8..f0d9344e 100644 --- a/tests/GIR/test_411_object_in_workspace.py +++ b/tests/GIR/test_411_object_in_workspace.py @@ -17,6 +17,7 @@ class TestObjectInWorkspaceContext(unittest.TestCase): mgd = None manager = None + transaction = None bookstoreName = "BookStore In Foo" extraFoo = "extra Foo" extraFooBar = "extra FooBar" @@ -31,8 +32,10 @@ def setUp(self): ws = Midgard.Workspace() self.manager.get_workspace_by_path(ws, "/Foo") self.mgd.set_workspace(ws) + self.mgd.beginTransaction() def tearDown(self): + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_412_object_in_workspace_context.py b/tests/GIR/test_412_object_in_workspace_context.py index 41763a6f..fc9c4b09 100644 --- a/tests/GIR/test_412_object_in_workspace_context.py +++ b/tests/GIR/test_412_object_in_workspace_context.py @@ -17,6 +17,7 @@ class TestObjectInWorkspaceContext(unittest.TestCase): mgd = None manager = None + transaction = None bookstoreName = "BookStore In Foo" extraFoo = "extra Foo" extraFooBar = "extra FooBar" @@ -25,14 +26,16 @@ class TestObjectInWorkspaceContext(unittest.TestCase): def setUp(self): if self.mgd is None: self.mgd = TestConnection.openConnection() - self.mgd.enable_workspace(True) + self.mgd.enable_workspace(True) + self.mgd.beginTransaction() if self.manager is None: self.manager = Midgard.WorkspaceManager(connection = self.mgd) ws = Midgard.Workspace() self.manager.get_workspace_by_path(ws, "/Foo") self.mgd.set_workspace(ws) - def tearDown(self): + def tearDown(self): + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_930_execution_pool.py b/tests/GIR/test_930_execution_pool.py index fe4110cd..30330b15 100644 --- a/tests/GIR/test_930_execution_pool.py +++ b/tests/GIR/test_930_execution_pool.py @@ -23,6 +23,7 @@ class TestExecutionPool(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.bookstore is None: self.bookstore = Midgard.Object.factory(self.mgd, "gir_test_book_store", None) self.bookstore.set_property("name", "BookStore One") @@ -43,6 +44,7 @@ def tearDown(self): self.reference = None self.job = None self.pool = None + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_940_content_manager.py b/tests/GIR/test_940_content_manager.py index 4e5e1ab6..a04db5dc 100644 --- a/tests/GIR/test_940_content_manager.py +++ b/tests/GIR/test_940_content_manager.py @@ -19,6 +19,7 @@ class TestContentManagerJobCreate(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.bookstore is None: self.bookstore = Midgard.Object.factory(self.mgd, "gir_test_book_store", None) if self.reference is None: @@ -31,6 +32,7 @@ def tearDown(self): self.reference = None self.job = None self.manager = None + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_950_content_manager_job_create.py b/tests/GIR/test_950_content_manager_job_create.py index 8a3f7fd9..d09b6fc0 100644 --- a/tests/GIR/test_950_content_manager_job_create.py +++ b/tests/GIR/test_950_content_manager_job_create.py @@ -25,6 +25,7 @@ class TestContentManagerJobCreate(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.bookstore_one is None: self.bookstore_one = Midgard.Object.factory(self.mgd, "gir_test_book_store", None) self.bookstore_one.set_property("name", "BookStore One") @@ -58,6 +59,7 @@ def tearDown(self): self.reference_two = None self.job_one = None self.job_two = None + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_951_content_manager_job_update.py b/tests/GIR/test_951_content_manager_job_update.py index 7499a2cc..ce782914 100644 --- a/tests/GIR/test_951_content_manager_job_update.py +++ b/tests/GIR/test_951_content_manager_job_update.py @@ -29,6 +29,7 @@ class TestContentManagerJobUpdate(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.bookstore_one is None: self.bookstore_one = Midgard.Object.factory(self.mgd, "gir_test_book_store", None) self.bookstore_one.set_property("name", "BookStore One") @@ -64,6 +65,7 @@ def tearDown(self): self.reference_two = None self.job_one = None self.job_two = None + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_952_content_manager_job_delete.py b/tests/GIR/test_952_content_manager_job_delete.py index 7ff5891e..b476cf51 100644 --- a/tests/GIR/test_952_content_manager_job_delete.py +++ b/tests/GIR/test_952_content_manager_job_delete.py @@ -30,6 +30,7 @@ class TestContentManagerJobDelete(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.bookstore_one is None: self.bookstore_one = Midgard.Object.factory(self.mgd, "gir_test_book_store", None) self.bookstore_one.set_property("name", self.bookstore_one_name) @@ -66,6 +67,7 @@ def tearDown(self): self.reference_two = None self.job_one = None self.job_two = None + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_953_content_manager_job_purge.py b/tests/GIR/test_953_content_manager_job_purge.py index d15c71c3..8fbc722a 100644 --- a/tests/GIR/test_953_content_manager_job_purge.py +++ b/tests/GIR/test_953_content_manager_job_purge.py @@ -29,6 +29,7 @@ class TestContentManagerJobPurge(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.bookstore_one is None: self.bookstore_one = Midgard.Object.factory(self.mgd, "gir_test_book_store", None) self.bookstore_one.set_property("name", self.bookstore_one_name) @@ -64,6 +65,7 @@ def tearDown(self): self.reference_two = None self.job_one = None self.job_two = None + self.mgd.commitTransaction() self.mgd.close() self.mgd = None diff --git a/tests/GIR/test_954_content_manager_job_load.py b/tests/GIR/test_954_content_manager_job_load.py index 376eb874..3089fd49 100644 --- a/tests/GIR/test_954_content_manager_job_load.py +++ b/tests/GIR/test_954_content_manager_job_load.py @@ -31,6 +31,7 @@ class TestContentManagerJobLoad(unittest.TestCase): def setUp(self): if self.mgd == None: self.mgd = TestConnection.openConnection() + self.mgd.beginTransaction() if self.bookstore_one is None: self.bookstore_one = Midgard.Object.factory(self.mgd, "gir_test_book_store", None) self.bookstore_one.set_property("name", "BookStore One") @@ -68,6 +69,7 @@ def tearDown(self): self.reference_two = None self.job_one = None self.job_two = None + self.mgd.commitTransaction() self.mgd.close() self.mgd = None