Skip to content

Commit

Permalink
fix class methods in TestQgsRelationEditWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored and nyalldawson committed Feb 3, 2021
1 parent af2d755 commit 1793b7c
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions tests/src/python/test_qgsrelationeditwidget.py
Expand Up @@ -91,24 +91,51 @@ def setUpClass(cls):
# Our mock QgsVectorLayerTools, that allow injecting data where user input is expected
cls.vltools = VlTools()

cls.layers = {cls.vl_authors, cls.vl_books, cls.vl_link_books_authors}

assert(cls.vl_authors.isValid())
assert(cls.vl_books.isValid())
assert(cls.vl_editors.isValid())
assert(cls.vl_link_books_authors.isValid())

def setUp(self):
self.startTransaction()

@classmethod
def tearDown(cls):
cls.rollbackTransaction()
del cls.transaction
def tearDownClass(cls):
QgsProject.instance().removeAllMapLayers()
cls.vl_books = None
cls.vl_authors = None
cls.vl_editors = None
cls.vl_link_books_authors = None

def setUp(self):
self.startTransaction()

def tearDown(self):
self.rollbackTransaction()
del self.transaction

def startTransaction(self):
"""
Start a new transaction and set all layers into transaction mode.
:return: None
"""
self.transaction = QgsTransaction.create(self.layers)
self.transaction.begin()
for layer in self.layers:
layer.startEditing()

def rollbackTransaction(self):
"""
Rollback all changes done in this transaction.
We always rollback and never commit to have the database in a pristine
state at the end of each test.
:return: None
"""
for layer in self.layers:
layer.commitChanges()
self.transaction.rollback()

def test_delete_feature(self):
"""
Check if a feature can be deleted properly
Expand Down Expand Up @@ -356,32 +383,6 @@ def addFeature(self, layer, defaultValues, defaultGeometry):

vl_leaks.rollBack()

def startTransaction(self):
"""
Start a new transaction and set all layers into transaction mode.
:return: None
"""
lyrs = [self.vl_authors, self.vl_books, self.vl_link_books_authors]

self.transaction = QgsTransaction.create(lyrs)
self.transaction.begin()
for l in lyrs:
l.startEditing()

def rollbackTransaction(self):
"""
Rollback all changes done in this transaction.
We always rollback and never commit to have the database in a pristine
state at the end of each test.
:return: None
"""
lyrs = [self.vl_authors, self.vl_books, self.vl_link_books_authors]
for l in lyrs:
l.commitChanges()
self.transaction.rollback()

def createWrapper(self, layer, filter=None):
"""
Basic setup of a relation widget wrapper.
Expand Down

0 comments on commit 1793b7c

Please sign in to comment.