Skip to content
Permalink
Browse files

Add order by test

  • Loading branch information
m-kuhn committed Dec 18, 2015
1 parent c0f2b29 commit f2ac1e8ee4d37067cd9f78397886438dd873eec8
Showing with 45 additions and 0 deletions.
  1. +45 −0 tests/src/python/providertestbase.py
@@ -120,6 +120,51 @@ def testGetFeaturesCompiled(self):
except AttributeError:
print 'Provider does not support compiling'

def testOrderBy(self):
request = QgsFeatureRequest().addOrderBy('cnt')
values = [f['cnt'] for f in self.provider.getFeatures(request)]
self.assertEquals(values, [-200, 100, 200, 300, 400])

request = QgsFeatureRequest().addOrderBy('cnt', False)
values = [f['cnt'] for f in self.provider.getFeatures(request)]
self.assertEquals(values, [400, 300, 200, 100, -200])

request = QgsFeatureRequest().addOrderBy('name')
values = [f['name'] for f in self.provider.getFeatures(request)]
self.assertEquals(values, ['Apple', 'Honey', 'Orange', 'Pear', NULL])

request = QgsFeatureRequest().addOrderBy('name', True, True)
values = [f['name'] for f in self.provider.getFeatures(request)]
self.assertEquals(values, [NULL, 'Apple', 'Honey', 'Orange', 'Pear'])

request = QgsFeatureRequest().addOrderBy('name', False)
values = [f['name'] for f in self.provider.getFeatures(request)]
self.assertEquals(values, [NULL, 'Pear', 'Orange', 'Honey', 'Apple'])

request = QgsFeatureRequest().addOrderBy('name', False, False)
values = [f['name'] for f in self.provider.getFeatures(request)]
self.assertEquals(values, ['Pear', 'Orange', 'Honey', 'Apple', NULL])

# Case sensitivity
request = QgsFeatureRequest().addOrderBy('name2')
values = [f['name2'] for f in self.provider.getFeatures(request)]
self.assertEquals(values, ['Apple', 'Honey', 'NuLl', 'oranGe', 'PEaR'])

# Combination with LIMIT
request = QgsFeatureRequest().addOrderBy('pk', False).setLimit(2)
values = [f['pk'] for f in self.provider.getFeatures(request)]
self.assertEquals(values, [5, 4])

# A slightly more complex expression
request = QgsFeatureRequest().addOrderBy('pk*2', False)
values = [f['pk'] for f in self.provider.getFeatures(request)]
self.assertEquals(values, [5, 4, 3, 2, 1])

# Multiple order bys and boolean
request = QgsFeatureRequest().addOrderBy('pk > 2').addOrderBy('pk', False)
values = [f['pk'] for f in self.provider.getFeatures(request)]
self.assertEquals(values, [2, 1, 5, 4, 3])

def testGetFeaturesFidTests(self):
fids = [f.id() for f in self.provider.getFeatures()]
assert len(fids) == 5, 'Expected 5 features, got {} instead'.format(len(fids))

0 comments on commit f2ac1e8

Please sign in to comment.
You can’t perform that action at this time.