Skip to content

Commit

Permalink
Execute all SQL operations inside transaction. Refs midgardprojectgh-185
Browse files Browse the repository at this point in the history
  • Loading branch information
piotras committed Feb 11, 2013
1 parent a562b1d commit 5ad748c
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 6 deletions.
12 changes: 11 additions & 1 deletion tests/GIR/test_020_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,29 @@
from gi.repository import Midgard, GObject

class TestConnection(Midgard.Connection):

transaction = None

def __init__(self):
Midgard.init()
Midgard.Connection.__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()
Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_100_object_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_110_object_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_120_object_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down
5 changes: 2 additions & 3 deletions tests/GIR/test_130_object_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_200_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_220_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_400_workspace_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_401_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_402_workspace_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions tests/GIR/test_411_object_in_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class TestObjectInWorkspaceContext(unittest.TestCase):
mgd = None
manager = None
transaction = None
bookstoreName = "BookStore In Foo"
extraFoo = "extra Foo"
extraFooBar = "extra FooBar"
Expand All @@ -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

Expand Down
7 changes: 5 additions & 2 deletions tests/GIR/test_412_object_in_workspace_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class TestObjectInWorkspaceContext(unittest.TestCase):
mgd = None
manager = None
transaction = None
bookstoreName = "BookStore In Foo"
extraFoo = "extra Foo"
extraFooBar = "extra FooBar"
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_930_execution_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_940_content_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_950_content_manager_job_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_951_content_manager_job_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_952_content_manager_job_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_953_content_manager_job_purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/GIR/test_954_content_manager_job_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 5ad748c

Please sign in to comment.