Skip to content

Commit

Permalink
#140 sort parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Emrys committed Mar 31, 2021
1 parent 41157b6 commit 39a43a5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
56 changes: 33 additions & 23 deletions crabpy_pyramid/tests/test_functional.py
Expand Up @@ -24,21 +24,14 @@ def as_bool(value):
return value in ['true', 'True', '1', 't', 'T', 'Yes']


def run_capakey_integration_tests():
def run_integration_tests(section):
from testconfig import config
try:
return as_bool(config['capakey']['run_integration_tests'])
return as_bool(config[section]['run_integration_tests'])
except KeyError: # pragma NO COVER
return False


def run_crab_integration_tests():
from testconfig import config
try:
return as_bool(config['crab']['run_integration_tests'])
except KeyError: # pragma NO COVER
return False

settings = {
'crabpy.cache.file.root': os.path.join(os.path.dirname(__file__), 'dogpile_data'),
'crabpy.capakey.cache_config.permanent.backend': 'dogpile.cache.dbm',
Expand Down Expand Up @@ -84,7 +77,7 @@ def tearDown(self):


@unittest.skipUnless(
run_capakey_integration_tests(),
run_integration_tests('capakey'),
'No CAPAKEY Integration tests required'
)
class CapakeyFunctionalTests(FunctionalTests):
Expand Down Expand Up @@ -125,40 +118,45 @@ def test_get_sectie_by_id_and_afdeling(self):
self.assertEqual('200 OK', res.status)

def test_get_sectie_by_unexisting_id_and_afdeling(self):
res = self.testapp.get('/capakey/afdelingen/11001/secties/Z', status=404)
res = self.testapp.get(
'/capakey/afdelingen/11001/secties/Z', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_percelen_by_sectie(self):
res = self.testapp.get('/capakey/afdelingen/11001/secties/B/percelen')
self.assertEqual('200 OK', res.status)

def test_get_perceel_by_sectie_and_id(self):
res = self.testapp.get('/capakey/afdelingen/11001/secties/B/percelen/0001/00S000')
res = self.testapp.get(
'/capakey/afdelingen/11001/secties/B/percelen/0001/00S000')
self.assertEqual('200 OK', res.status)

def test_get_perceel_by_unexisting_sectie_and_id(self):
res = self.testapp.get('/capakey/afdelingen/11001/secties/B/percelen/0000/00000', status=404)
res = self.testapp.get(
'/capakey/afdelingen/11001/secties/B/percelen/0000/00000', status=404)
self.assertEqual('404 Not Found', res.status)

def test_get_perceel_by_capakey(self):
res = self.testapp.get('/capakey/percelen/11001B0001/00S000')
self.assertEqual('200 OK', res.status)

def test_get_perceel_by_unexisting_capakey(self):
res = self.testapp.get('/capakey/percelen/99009X0009/00X000', status=404)
res = self.testapp.get(
'/capakey/percelen/99009X0009/00X000', status=404)
self.assertEqual('404 Not Found', res.status)

def test_get_perceel_by_percid(self):
res = self.testapp.get('/capakey/percelen/11001_B_0001_S_000_00')
self.assertEqual('200 OK', res.status)

def test_get_perceel_by_unexisting_percid(self):
res = self.testapp.get('/capakey/percelen/99009_X_0009_X_000_00', status=404)
res = self.testapp.get(
'/capakey/percelen/99009_X_0009_X_000_00', status=404)
self.assertEqual('404 Not Found', res.status)


@unittest.skipUnless(
run_crab_integration_tests(),
run_integration_tests('crab'),
'No CRAB Integration tests required'
)
class CrabFunctionalTests(FunctionalTests):
Expand Down Expand Up @@ -223,9 +221,11 @@ def test_list_deelgemeenten_by_gemeente(self):
self.assertEqual('200 OK', res.status)

def test_list_deelgemeenten_by_unexisting_gemeente(self):
res = self.testapp.get('/crab/gemeenten/99999/deelgemeenten', status=404)
res = self.testapp.get(
'/crab/gemeenten/99999/deelgemeenten', status=404)
self.assertEqual('404 Not Found', res.status)
res = self.testapp.get('/crab/gemeenten/9999/deelgemeenten', status=404)
res = self.testapp.get(
'/crab/gemeenten/9999/deelgemeenten', status=404)
self.assertEqual('404 Not Found', res.status)

def test_get_deelgemeente_by_id(self):
Expand All @@ -248,6 +248,13 @@ def test_list_huisnummers(self):
res = self.testapp.get('/crab/straten/1/huisnummers')
self.assertEqual('200 OK', res.status)

def test_sort_huisnummers(self):
res = self.testapp.get('/crab/straten/1/huisnummers?sort=2')
self.assertEqual('200 OK', res.status)
nummers = [int(item['label']) for item in res.json]
ascending = sorted(nummers)
self.assertEqual(nummers, ascending)

def test_get_huisnummer_by_straat_and_label(self):
res = self.testapp.get('/crab/straten/1/huisnummers/3')
self.assertEqual('200 OK', res.status)
Expand Down Expand Up @@ -281,7 +288,8 @@ def test_list_huisnummers_by_perceel(self):
self.assertEqual('200 OK', res.status)

def test_list_huisnummers_by_unexisting_perceel(self):
res = self.testapp.get('/crab/percelen/31433D0011/000000/huisnummers', status=404)
res = self.testapp.get(
'/crab/percelen/31433D0011/000000/huisnummers', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_gebouwen(self):
Expand Down Expand Up @@ -353,11 +361,13 @@ def test_get_postkanton_by_huisnummer(self):
self.assertEqual('200 OK', res.status)

def test_get_postkanton_by_huisnummer_unexisting(self):
res = self.testapp.get('/crab/huisnummers/99999999/postkanton', status=404)
res = self.testapp.get(
'/crab/huisnummers/99999999/postkanton', status=404)
self.assertEqual('404 Not Found', res.status)


@unittest.skipUnless(
run_crab_integration_tests(),
run_integration_tests('crab'),
'No CRAB Integration tests required'
)
class HttpCachingFunctionalTests(FunctionalTests):
Expand All @@ -370,7 +380,8 @@ def test_http_304_res(self):
res = self.testapp.get('/crab/gewesten')
self.assertEqual('200 OK', res.status)
etag = res.headers['Etag']
res2 = self.testapp.get('/crab/gewesten', headers={'If-None-Match': etag})
res2 = self.testapp.get(
'/crab/gewesten', headers={'If-None-Match': etag})
self.assertEqual('304 Not Modified', res2.status)

def test_list_gewesten_not_cached(self):
Expand All @@ -381,4 +392,3 @@ def test_list_gewesten_not_cached(self):
self.assertNotIn('ETag', res.headers)
finally:
crabpy_pyramid.GENERATE_ETAG_ROUTE_NAMES.add('list_gewesten')

6 changes: 4 additions & 2 deletions crabpy_pyramid/views/capakey.py
Expand Up @@ -16,7 +16,8 @@
def list_gemeenten(request):
request = set_http_caching(request, 'capakey', 'permanent')
Gateway = request.capakey_gateway()
gemeenten = Gateway.list_gemeenten(1)
sort = request.params.get('sort', 1)
gemeenten = Gateway.list_gemeenten(sort)
return range_return(request, gemeenten)


Expand All @@ -39,7 +40,8 @@ def list_kadastrale_afdelingen_by_gemeente(request):
request = set_http_caching(request, 'capakey', 'permanent')
Gateway = request.capakey_gateway()
gemeente_id = request.matchdict.get('gemeente_id')
afdelingen = Gateway.list_kadastrale_afdelingen_by_gemeente(gemeente_id)
sort = request.params.get('sort', 1)
afdelingen = Gateway.list_kadastrale_afdelingen_by_gemeente(gemeente_id, sort)
return range_return(request, afdelingen)


Expand Down
9 changes: 6 additions & 3 deletions crabpy_pyramid/views/crab.py
Expand Up @@ -24,7 +24,8 @@
def list_gewesten(request):
request = set_http_caching(request, 'crab', 'permanent')
Gateway = request.crab_gateway()
gewesten = Gateway.list_gewesten()
sort = request.params.get('sort', 1)
gewesten = Gateway.list_gewesten(sort)
return range_return(request, gewesten)


Expand Down Expand Up @@ -200,7 +201,8 @@ def list_huisnummers(request):
request = set_http_caching(request, 'crab', 'short')
Gateway = request.crab_gateway()
straat_id = request.matchdict.get('straat_id')
huisnummers = Gateway.list_huisnummers_by_straat(straat_id)
sort = request.params.get('sort', 1)
huisnummers = Gateway.list_huisnummers_by_straat(straat_id, sort)
return range_return(request, huisnummers)


Expand Down Expand Up @@ -267,9 +269,10 @@ def list_huisnummers_by_perceel(request):
request = set_http_caching(request, 'crab', 'short')
Gateway = request.crab_gateway()
perceel_id = request.matchdict.get('perceel_id1') + '/' + request.matchdict.get('perceel_id2')
sort = request.params.get('sort', 1)
try:
perceel = Gateway.get_perceel_by_id(perceel_id)
return Gateway.list_huisnummers_by_perceel(perceel)
return Gateway.list_huisnummers_by_perceel(perceel, sort)
except GatewayResourceNotFoundException:
return HTTPNotFound()

Expand Down

0 comments on commit 39a43a5

Please sign in to comment.