Skip to content

Commit

Permalink
Merge branch '25_handling_unexisting_objects'
Browse files Browse the repository at this point in the history
* 25_handling_unexisting_objects:
  added tests handling unexisting objects capakey refs #25
  handling unexisting objects refs #25
  handling unexisting objects crab refs #25
  • Loading branch information
Koen Van Daele committed Jun 1, 2015
2 parents dd61b31 + 73d5638 commit ce49fa2
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 17 deletions.
76 changes: 73 additions & 3 deletions crabpy_pyramid/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
.. versionadded:: 0.1.0
'''
import unittest
import json
import os
import shutil

from paste.deploy.loadwsgi import appconfig

from pyramid import testing
from webtest import TestApp

from crabpy_pyramid import main


def as_bool(value):
'''
Cast a textual value from a config file to a boolean.
Expand All @@ -24,6 +22,7 @@ def as_bool(value):
'''
return value in ['true', 'True', '1', 't', 'T', 'Yes']


def run_capakey_integration_tests():
from testconfig import config
try:
Expand Down Expand Up @@ -66,6 +65,7 @@ def setUpModule():
True
)


class FunctionalTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand All @@ -78,6 +78,7 @@ def setUp(self):
def tearDown(self):
testing.tearDown()


@unittest.skipUnless(
run_capakey_integration_tests(),
'No CAPAKEY Integration tests required'
Expand All @@ -91,6 +92,10 @@ def test_get_gemeente_by_id(self):
res = self.testapp.get('/capakey/gemeenten/11001')
self.assertEqual('200 OK', res.status)

def test_get_gemeente_by_unexisting_id(self):
res = self.testapp.get('/capakey/gemeenten/1100', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_kadastrale_afdelingen_by_gemeente(self):
res = self.testapp.get('/capakey/gemeenten/11001/afdelingen')
self.assertEqual('200 OK', res.status)
Expand All @@ -103,6 +108,10 @@ def test_get_sectie_by_id_and_afdeling(self):
res = self.testapp.get('/capakey/afdelingen/11001/secties/B')
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)
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)
Expand All @@ -111,14 +120,26 @@ def test_get_perceel_by_sectie_and_id(self):
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)
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/00000000000/000000', 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/00000_0_0000_0_000_00', status=404)
self.assertEqual('404 Not Found', res.status)


@unittest.skipUnless(
run_crab_integration_tests(),
Expand All @@ -133,6 +154,10 @@ def test_get_gewest_by_id(self):
res = self.testapp.get('/crab/gewesten/2')
self.assertEqual('200 OK', res.status)

def test_get_gewest_by_unexisting_id(self):
res = self.testapp.get('/crab/gewesten/0', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_provincies(self):
res = self.testapp.get('/crab/gewesten/2/provincies')
self.assertEqual('200 OK', res.status)
Expand All @@ -141,6 +166,10 @@ def test_get_provincie_by_id(self):
res = self.testapp.get('/crab/provincies/10000')
self.assertEqual('200 OK', res.status)

def test_get_provincie_by_unexisting_id(self):
res = self.testapp.get('/crab/provincies/00000', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_gemeenten_by_provincie(self):
res = self.testapp.get('/crab/provincies/10000/gemeenten')
self.assertEqual('200 OK', res.status)
Expand All @@ -153,10 +182,18 @@ def test_get_gemeente_crab_niscode(self):
res = self.testapp.get('/crab/gemeenten/11001')
self.assertEqual('200 OK', res.status)

def test_get_gemeente_crab_unexisting_niscode(self):
res = self.testapp.get('/crab/gemeenten/00000', status=404)
self.assertEqual('404 Not Found', res.status)

def test_get_gemeente_crab_id(self):
res = self.testapp.get('/crab/gemeenten/1')
self.assertEqual('200 OK', res.status)

def test_get_gemeente_crab_unexisting_id(self):
res = self.testapp.get('/crab/gemeenten/0', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_straten(self):
res = self.testapp.get('/crab/gemeenten/11001/straten')
self.assertEqual('200 OK', res.status)
Expand All @@ -165,6 +202,10 @@ def test_get_straat_by_id(self):
res = self.testapp.get('/crab/straten/1')
self.assertEqual('200 OK', res.status)

def test_get_straat_by_unexisting_id(self):
res = self.testapp.get('/crab/straten/0', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_huisnummers(self):
res = self.testapp.get('/crab/straten/1/huisnummers')
self.assertEqual('200 OK', res.status)
Expand All @@ -173,10 +214,18 @@ def test_get_huisnummer_by_straat_and_label(self):
res = self.testapp.get('/crab/straten/1/huisnummers/3')
self.assertEqual('200 OK', res.status)

def test_get_huisnummer_by_unexisting_straat_and_label(self):
res = self.testapp.get('/crab/straten/1/huisnummers/0', status=404)
self.assertEqual('404 Not Found', res.status)

def test_get_huisnummer_by_id(self):
res = self.testapp.get('/crab/huisnummers/1')
self.assertEqual('200 OK', res.status)

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

def test_list_percelen(self):
res = self.testapp.get('/crab/huisnummers/1/percelen')
self.assertEqual('200 OK', res.status)
Expand All @@ -185,6 +234,10 @@ def test_get_perceel_by_id(self):
res = self.testapp.get('/crab/percelen/31433D0011/00T016')
self.assertEqual('200 OK', res.status)

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

def test_list_gebouwen(self):
res = self.testapp.get('/crab/huisnummers/1/gebouwen')
self.assertEqual('200 OK', res.status)
Expand All @@ -193,10 +246,18 @@ def test_get_gebouw_by_id(self):
res = self.testapp.get('/crab/gebouwen/1538575')
self.assertEqual('200 OK', res.status)

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

def test_get_wegobject(self):
res = self.testapp.get('/crab/wegobjecten/53694755')
self.assertEqual('200 OK', res.status)

def test_get_unexisting_wegobject(self):
res = self.testapp.get('/crab/wegobjecten/00000000', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_subadressen(self):
res = self.testapp.get('/crab/huisnummers/129462/subadressen')
self.assertEqual('200 OK', res.status)
Expand All @@ -205,6 +266,10 @@ def test_get_subadressen_by_id(self):
res = self.testapp.get('/crab/subadressen/1120934')
self.assertEqual('200 OK', res.status)

def test_get_subadressen_by_unexisting_id(self):
res = self.testapp.get('/crab/subadressen/0000000', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_postkantons_by_gemeente(self):
res = self.testapp.get('/crab/gemeenten/90/postkantons')
self.assertEqual('200 OK', res.status)
Expand All @@ -221,6 +286,10 @@ def test_get_adrespositie_by_id(self):
res = self.testapp.get('/crab/adresposities/137')
self.assertEqual('200 OK', res.status)

def test_get_adrespositie_by_unexisting_id(self):
res = self.testapp.get('/crab/adresposities/0', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_landen(self):
res = self.testapp.get('/crab/landen')
self.assertEqual('200 OK', res.status)
Expand All @@ -231,3 +300,4 @@ def test_get_land_by_id(self):

def test_get_land_by_unexisting_id(self):
res = self.testapp.get('/crab/landen/MORDOR', status=404)
self.assertEqual('404 Not Found', res.status)
64 changes: 50 additions & 14 deletions crabpy_pyramid/views/crab.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from crabpy_pyramid.utils import range_return
import pycountry

from crabpy.gateway.exception import GatewayResourceNotFoundException

from pyramid.httpexceptions import HTTPNotFound

@view_config(
Expand All @@ -26,7 +28,10 @@ def list_gewesten(request):
def get_gewest_by_id(request):
Gateway = request.crab_gateway()
gewest_id = int(request.matchdict.get('gewest_id'))
return Gateway.get_gewest_by_id(gewest_id)
try:
return Gateway.get_gewest_by_id(gewest_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()

@view_config(
route_name='list_provincies',
Expand All @@ -45,8 +50,10 @@ def list_provincies(request):
def get_provincie(request):
Gateway = request.crab_gateway()
provincie_id = int(request.matchdict.get('provincie_id'))
provincie = Gateway.get_provincie_by_id(provincie_id)
return provincie
try:
return Gateway.get_provincie_by_id(provincie_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()

@view_config(
route_name='list_gemeenten_by_provincie',
Expand Down Expand Up @@ -79,9 +86,15 @@ def get_gemeente_crab(request):
Gateway = request.crab_gateway()
gemeente_id = request.matchdict.get('gemeente_id')
if len(gemeente_id) == 5:
return Gateway.get_gemeente_by_niscode(gemeente_id)
try:
return Gateway.get_gemeente_by_niscode(gemeente_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()
else:
return Gateway.get_gemeente_by_id(gemeente_id)
try:
return Gateway.get_gemeente_by_id(gemeente_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()

@view_config(
route_name='list_straten',
Expand All @@ -102,7 +115,10 @@ def list_straten(request):
def get_straat_by_id(request):
Gateway = request.crab_gateway()
straat_id = request.matchdict.get('straat_id')
return Gateway.get_straat_by_id(straat_id)
try:
return Gateway.get_straat_by_id(straat_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()

@view_config(
route_name='list_huisnummers',
Expand All @@ -122,7 +138,10 @@ def get_huisnummer_by_straat_and_label(request):
Gateway = request.crab_gateway()
straat_id = request.matchdict.get('straat_id')
huisnummer = request.matchdict.get('huisnummer_label')
return Gateway.get_huisnummer_by_nummer_and_straat(huisnummer, straat_id)
try:
return Gateway.get_huisnummer_by_nummer_and_straat(huisnummer, straat_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()


@view_config(
Expand All @@ -132,7 +151,10 @@ def get_huisnummer_by_straat_and_label(request):
def get_huisnummer_by_id(request):
Gateway = request.crab_gateway()
huisnummer_id = request.matchdict.get('huisnummer_id')
return Gateway.get_huisnummer_by_id(huisnummer_id)
try:
return Gateway.get_huisnummer_by_id(huisnummer_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()

@view_config(
route_name='list_percelen',
Expand All @@ -151,7 +173,10 @@ def list_percelen(request):
def get_perceel_by_id(request):
Gateway = request.crab_gateway()
perceel_id = request.matchdict.get('perceel_id1')+'/'+request.matchdict.get('perceel_id2')
return Gateway.get_perceel_by_id(perceel_id)
try:
return Gateway.get_perceel_by_id(perceel_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()

@view_config(
route_name='list_gebouwen',
Expand All @@ -170,7 +195,10 @@ def list_gebouwen(request):
def get_gebouw_by_id(request):
Gateway = request.crab_gateway()
gebouw_id = request.matchdict.get('gebouw_id')
return Gateway.get_gebouw_by_id(gebouw_id)
try:
return Gateway.get_gebouw_by_id(gebouw_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()

@view_config(
route_name='get_wegobject',
Expand All @@ -179,8 +207,10 @@ def get_gebouw_by_id(request):
def get_wegobject(request):
Gateway = request.crab_gateway()
wegobject_id = request.matchdict.get('wegobject_id')
return Gateway.get_wegobject_by_id(wegobject_id)

try:
return Gateway.get_wegobject_by_id(wegobject_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()

@view_config(
route_name='list_subadressen',
Expand All @@ -199,7 +229,10 @@ def list_subadressen(request):
def get_subadres_by_id(request):
Gateway = request.crab_gateway()
subadres_id = request.matchdict.get('subadres_id')
return Gateway.get_subadres_by_id(subadres_id)
try:
return Gateway.get_subadres_by_id(subadres_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()


@view_config(
Expand Down Expand Up @@ -242,7 +275,10 @@ def list_adresposities_by_subadres(request):
def get_adrespositie_by_id(request):
Gateway = request.crab_gateway()
adrespositie_id = request.matchdict.get('adrespositie_id')
return Gateway.get_adrespositie_by_id(adrespositie_id)
try:
return Gateway.get_adrespositie_by_id(adrespositie_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()


@view_config(
Expand Down

0 comments on commit ce49fa2

Please sign in to comment.