Skip to content
Permalink
Browse files

Update tests

  • Loading branch information
nyalldawson committed Feb 6, 2021
1 parent d0882d0 commit 15267f9e6c1240122b9f62da977f300f1ce16e1c
@@ -80,6 +80,7 @@ void TestQgsFeatureListComboBox::init()
{
// create layer
mLayer.reset( new QgsVectorLayer( QStringLiteral( "LineString?field=pk:int&field=material:string&field=diameter:int&field=raccord:string" ), QStringLiteral( "vl2" ), QStringLiteral( "memory" ) ) );
mLayer->setDisplayExpression( QStringLiteral( "pk" ) );

// add features
mLayer->startEditing();
@@ -100,6 +100,7 @@ void TestQgsRelationReferenceWidget::init()
QgsProject::instance()->addMapLayer( mLayer1.get(), false, false );

mLayer2.reset( new QgsVectorLayer( QStringLiteral( "LineString?field=pk:int&field=material:string&field=diameter:int&field=raccord:string" ), QStringLiteral( "vl2" ), QStringLiteral( "memory" ) ) );
mLayer2->setDisplayExpression( QStringLiteral( "pk" ) );
QgsProject::instance()->addMapLayer( mLayer2.get(), false, false );

// create relation
@@ -203,6 +203,7 @@ def test_representValue(self):
self.assertTrue(first_layer.isValid())
second_layer = QgsVectorLayer("none?field=pkid:integer&field=decoded:string",
"second_layer", "memory")
second_layer.setDisplayExpression('pkid')
self.assertTrue(second_layer.isValid())
QgsProject.instance().addMapLayers([first_layer, second_layer])
f = QgsFeature()
@@ -241,10 +242,10 @@ def test_representValue(self):
second_layer.setDisplayExpression('decoded')
self.assertEqual(fieldFormatter.representValue(first_layer, 0, config, None, '123'), '123')

# No display expression
# No display expression - will default internally to the decoded string
config = {'Relation': rel.id()}
second_layer.setDisplayExpression(None)
self.assertEqual(fieldFormatter.representValue(first_layer, 0, config, None, '123'), '123')
self.assertEqual(fieldFormatter.representValue(first_layer, 0, config, None, '123'), 'decoded_val')

# Invalid display expression
config = {'Relation': rel.id()}
@@ -3084,9 +3084,6 @@ def testDefaultDisplayExpression(self):
layer = QgsVectorLayer("Polygon?crs=epsg:2056&field=pk:int", "vl", "memory")
self.assertEqual(layer.displayExpression(), '"pk"')
self.assertEqual(layer.displayField(), 'pk')
layer = QgsVectorLayer("Polygon?crs=epsg:2056&field=pk:int&field=fid:int", "vl", "memory")
self.assertEqual(layer.displayExpression(), '"fid"')
self.assertEqual(layer.displayField(), 'fid')
layer = QgsVectorLayer("Polygon?crs=epsg:2056&field=pk:int&field=DESCRIPTION:string&field=fid:int", "vl", "memory")
self.assertEqual(layer.displayExpression(), '"DESCRIPTION"')
self.assertEqual(layer.displayField(), 'DESCRIPTION')

0 comments on commit 15267f9

Please sign in to comment.