Skip to content
Permalink
Browse files

fix class methods in TestQgsRelationEditWidget

  • Loading branch information
3nids authored and nyalldawson committed Feb 8, 2021
1 parent 5862148 commit 831b279e875d97920ebcd719c8254fef69d8926e
Showing with 33 additions and 32 deletions.
  1. +33 −32 tests/src/python/test_qgsrelationeditwidget.py
@@ -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
@@ -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.

0 comments on commit 831b279

Please sign in to comment.