@@ -86,6 +86,46 @@ def tearDown(self):
8686 """Run after each test."""
8787 pass
8888
89+ def test_filterfid_crossjoin (self ):
90+ l0 = QgsVectorLayer (os .path .join (self .testDataDir , "france_parts.shp" ), "france_parts" , "ogr" )
91+ self .assertTrue (l0 .isValid ())
92+ QgsMapLayerRegistry .instance ().addMapLayer (l0 )
93+
94+ l1 = QgsVectorLayer (os .path .join (self .testDataDir , "points.shp" ), "points" , "ogr" )
95+ self .assertTrue (l1 .isValid ())
96+ QgsMapLayerRegistry .instance ().addMapLayer (l1 )
97+
98+ # cross join
99+ query = QUrl .toPercentEncoding ("SELECT * FROM france_parts,points" )
100+ vl = QgsVectorLayer ("?query=%s" % query , "tt" , "virtual" )
101+
102+ self .assertEqual (vl .featureCount (), l0 .featureCount () * l1 .featureCount ())
103+
104+ # test with FilterFid requests
105+ f = next (vl .getFeatures (QgsFeatureRequest ().setFilterFid (0 )))
106+ idx = f .fields ().fieldNameIndex ('Class' )
107+ self .assertEqual (f .id (), 0 )
108+ self .assertEqual (f .attributes ()[idx ], 'Jet' )
109+
110+ f = next (vl .getFeatures (QgsFeatureRequest ().setFilterFid (5 )))
111+ self .assertEqual (f .id (), 5 )
112+ self .assertEqual (f .attributes ()[idx ], 'Biplane' )
113+
114+ # test with FilterFid requests
115+ fit = vl .getFeatures (QgsFeatureRequest ().setFilterFids ([0 , 3 , 5 ]))
116+
117+ f = next (fit )
118+ self .assertEqual (f .id (), 0 )
119+ self .assertEqual (f .attributes ()[idx ], 'Jet' )
120+
121+ f = next (fit )
122+ self .assertEqual (f .id (), 3 )
123+ self .assertEqual (f .attributes ()[idx ], 'Jet' )
124+
125+ f = next (fit )
126+ self .assertEqual (f .id (), 5 )
127+ self .assertEqual (f .attributes ()[idx ], 'Biplane' )
128+
89129 def test_CsvNoGeometry (self ):
90130 l1 = QgsVectorLayer (QUrl .fromLocalFile (os .path .join (self .testDataDir , "delimitedtext/test.csv" )).toString () + "?type=csv&geomType=none&subsetIndex=no&watchFile=no" , "test" , "delimitedtext" , False )
91131 self .assertEqual (l1 .isValid (), True )
0 commit comments