Skip to content
Permalink
Browse files
Move test
  • Loading branch information
elpaso committed Jul 9, 2021
1 parent 48deba5 commit e79c3c3a166a714b98f43a6969868413a6baddc3
Showing with 101 additions and 18 deletions.
  1. +1 −18 tests/src/core/testqgslayerdefinition.cpp
  2. +100 −0 tests/src/python/test_qgslayerdefinition.py
@@ -21,7 +21,6 @@

#include <qgsapplication.h>
#include <qgsproject.h>
#include <qgsvectorlayer.h>
#include <qgslayertree.h>
#include <qgslayerdefinition.h>

@@ -43,17 +42,11 @@ class TestQgsLayerDefinition: public QObject
void testFindLayers();

/**
* test that export does not crash
* test that export does not crash: regression #18981
* https://github.com/qgis/QGIS/issues/26812 - Save QLR crashes QGIS 3
*/
void testExportDoesNotCrash();

/**
* Test valueRelation in Attribute form wrong loaded from layer definition file (qlr)
* https://github.com/qgis/QGIS/issues/43978
*/
void testWidgetConfig();

private:
QTemporaryFile *mTempFile;
};
@@ -109,16 +102,6 @@ void TestQgsLayerDefinition::testExportDoesNotCrash()
testFindLayers();
}

void TestQgsLayerDefinition::testWidgetConfig()
{
const auto vl { static_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayersByName( QStringLiteral( "NewMemory" ) ).first() ) };
QVERIFY( vl );
const auto field { vl->fields().at( 0 ) };
const auto config { field.editorWidgetSetup().config() };
QCOMPARE( config[ QStringLiteral( "Description" ) ].toString(), QString() );
QCOMPARE( config[ QStringLiteral( "FilterExpression" ) ].toString(), QString() );
}



QGSTEST_MAIN( TestQgsLayerDefinition )
@@ -25,6 +25,7 @@
from utilities import unitTestDataPath

from qgis.PyQt.QtXml import QDomDocument
from qgis.PyQt.QtCore import QTemporaryDir

start_app()
TEST_DATA_DIR = unitTestDataPath()
@@ -162,6 +163,105 @@ def test_path_storage(self):
with open(temp_dir.filePath('absolute.qlr'), 'rt') as f:
lines = f.readlines()
self.assertIn(f'source="{gpkg_path}"', '\n'.join(lines))

def testWidgetConfig(self):

temp = QTemporaryDir()
temp_path = temp.path()
temp_qlr = os.path.join(temp_path, 'widget_config.qlr')

qlr = """<!DOCTYPE qgis-layer-definition>
<qlr>
<layer-tree-group expanded="1" checked="Qt::Checked" name="">
<customproperties/>
<layer-tree-group name="group">
<customproperties/>
<layer-tree-layer providerKey="memory" name="OldMemory" source="NoGeometry?crs=EPSG:4326&amp;field=BA_ART_LAT:string&amp;uid={908cbaab-cabe-4bd9-9058-2b80ebf87a72}" id="OldMemory_ffa4d8a4_e5be_46a9_a0e0_fb6ee924f3cd" />
<layer-tree-layer providerKey="memory" name="NewMemory" source="NoGeometry?crs=EPSG:4326&amp;field=BA_ART_LAT:string&amp;uid={64c9bcbf-cabe-4bd9-9058-2b80ebf87a72}" id="NewMemory_ffa4d8a4_e5be_46a9_a0e0_fb6ee924f3cd" />
<customproperties/>
</layer-tree-group>
</layer-tree-group>
<maplayers>
<maplayer type="vector" autoRefreshTime="0" geometry="No geometry">
<id>OldMemory_ffa4d8a4_e5be_46a9_a0e0_fb6ee924f3cd</id>
<datasource>memory?geometry=NoGeometry&amp;field=BA_ART_LAT:string&amp;crs=EPSG:4326</datasource>
<keywordList>
<value></value>
</keywordList>
<layername>OldMemory</layername>
<srs>
<spatialrefsys>
<proj4>+proj=longlat +datum=WGS84 +no_defs</proj4>
<srsid>3452</srsid>
<srid>4326</srid>
<authid>EPSG:4326</authid>
<description>WGS 84</description>
<projectionacronym>longlat</projectionacronym>
<ellipsoidacronym>WGS84</ellipsoidacronym>
<geographicflag>true</geographicflag>
</spatialrefsys>
</srs>
<provider encoding="UTF-8">memory</provider>
</maplayer>
<maplayer type="vector"geometry="No geometry">
<id>NewMemory_ffa4d8a4_e5be_46a9_a0e0_fb6ee924f3cd</id>
<datasource>memory?geometry=NoGeometry&amp;field=BA_ART_LAT:string&amp;crs=EPSG:4326</datasource>
<layername>NewMemory</layername>
<srs>
<spatialrefsys>
<proj4>+proj=longlat +datum=WGS84 +no_defs</proj4>
<srsid>3452</srsid>
<srid>4326</srid>
<authid>EPSG:4326</authid>
<description>WGS 84</description>
<projectionacronym>longlat</projectionacronym>
<ellipsoidacronym>WGS84</ellipsoidacronym>
<geographicflag>true</geographicflag>
</spatialrefsys>
</srs>
<provider encoding="UTF-8">memory</provider>
<fieldConfiguration>
<field name="BA_ART_LAT" configurationFlags="None">
<editWidget type="ValueRelation">
<config>
<Option type="Map">
<Option value="false" name="AllowMulti" type="bool"/>
<Option value="false" name="AllowNull" type="bool"/>
<Option value="" name="Description" type="QString"/>
<Option value="" name="FilterExpression" type="QString"/>
<Option value="Wert" name="Key" type="QString"/>
<Option value="OldMemory_ffa4d8a4_e5be_46a9_a0e0_fb6ee924f3cd" name="Layer" type="QString"/>
<Option value="SL_BA_ART_LAT" name="LayerName" type="QString"/>
<Option value="ogr" name="LayerProviderName" type="QString"/>
<Option value="NoGeometry?crs=EPSG:4326&amp;field=BA_ART_LAT:string&amp;uid={908cbaab-cabe-4bd9-9058-2b80ebf87a72}" name="LayerSource" type="QString"/>
<Option value="1" name="NofColumns" type="int"/>
<Option value="false" name="OrderByValue" type="bool"/>
<Option value="false" name="UseCompleter" type="bool"/>
<Option value="Bezeichnung" name="Value" type="QString"/>
</Option>
</config>
</editWidget>
</field>
</fieldConfiguration>
</maplayer>
</maplayers>
</qlr>
"""

with open(temp_qlr, 'w+') as f:
f.write(qlr)

(result, errMsg) = QgsLayerDefinition.loadLayerDefinition(temp_qlr, QgsProject.instance(), QgsProject.instance().layerTreeRoot())
self.assertTrue(result)
self.assertFalse(errMsg)

vl = QgsProject.instance().mapLayersByName('NewMemory')[0]
field = vl.fields().at(0)
config = field.editorWidgetSetup().config()

self.assertEqual(config['Description'], '')
self.assertEqual(config['FilterExpression'], '')


if __name__ == '__main__':

0 comments on commit e79c3c3

Please sign in to comment.