Skip to content
Permalink
Browse files

Modernise test

(cherry picked from commit a09ffc8)
  • Loading branch information
nyalldawson committed Feb 16, 2021
1 parent f6a4613 commit 0140dd693531518344884e25d30e8fd3c6f0c983
Showing with 13 additions and 13 deletions.
  1. +13 −13 tests/src/python/test_qgsrelation.py
@@ -85,22 +85,22 @@ def tearDown(self):

def test_isValid(self):
rel = QgsRelation()
assert not rel.isValid()
self.assertFalse(rel.isValid())

rel.setId('rel1')
assert not rel.isValid()
self.assertFalse(rel.isValid())

rel.setName('Relation Number One')
assert not rel.isValid()
self.assertFalse(rel.isValid())

rel.setReferencingLayer(self.referencingLayer.id())
assert not rel.isValid()
self.assertFalse(rel.isValid())

rel.setReferencedLayer(self.referencedLayer.id())
assert not rel.isValid()
self.assertFalse(rel.isValid())

rel.addFieldPair('foreignkey', 'y')
assert rel.isValid()
self.assertTrue(rel.isValid())

def test_getRelatedFeatures(self):
rel = QgsRelation()
@@ -116,7 +116,7 @@ def test_getRelatedFeatures(self):
self.assertEqual(rel.getRelatedFeaturesFilter(feat), '"foreignkey" = 123')

it = rel.getRelatedFeatures(feat)
assert [a.attributes() for a in it] == [['test1', 123], ['test2', 123]]
self.assertEqual([a.attributes() for a in it], [['test1', 123], ['test2', 123]])

def test_getRelatedFeaturesWithQuote(self):
rel = QgsRelation()
@@ -130,7 +130,7 @@ def test_getRelatedFeaturesWithQuote(self):
feat = self.referencedLayer.getFeature(3)

it = rel.getRelatedFeatures(feat)
assert next(it).attributes() == ["foobar'bar", 124]
self.assertEqual(next(it).attributes(), ["foobar'bar", 124])

def test_getReferencedFeature(self):
rel = QgsRelation()
@@ -144,8 +144,8 @@ def test_getReferencedFeature(self):

f = rel.getReferencedFeature(feat)

assert f.isValid()
assert f[0] == 'foo'
self.assertTrue(f.isValid())
self.assertEqual(f[0], 'foo')

# try mixing up the field pair field name cases -- we should be tolerant to this
rel2 = QgsRelation()
@@ -159,8 +159,8 @@ def test_getReferencedFeature(self):

f = rel2.getReferencedFeature(feat)

assert f.isValid()
assert f[0] == 'foo'
self.assertTrue(f.isValid())
self.assertEqual(f[0], 'foo')

def test_fieldPairs(self):
rel = QgsRelation()
@@ -171,7 +171,7 @@ def test_fieldPairs(self):
rel.setReferencedLayer(self.referencedLayer.id())
rel.addFieldPair('foreignkey', 'y')

assert (rel.fieldPairs() == {'foreignkey': 'y'})
self.assertEqual(rel.fieldPairs(), {'foreignkey': 'y'})

def testValidRelationAfterChangingStyle(self):
# load project

0 comments on commit 0140dd6

Please sign in to comment.