Skip to content

Commit

Permalink
Fix tests. Refs #84
Browse files Browse the repository at this point in the history
  • Loading branch information
koenedaele committed Aug 1, 2018
1 parent eb9bac0 commit 37f8e9c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
16 changes: 11 additions & 5 deletions crabpy_pyramid/renderers/capakey.py
Expand Up @@ -8,6 +8,8 @@

from pyramid.renderers import JSON

import json

json_list_renderer = JSON()
json_item_renderer = JSON()

Expand Down Expand Up @@ -57,7 +59,7 @@ def list_perceel_adapter(obj, request):
'capakey': obj.capakey,
'percid': obj.percid
}

json_list_renderer.add_adapter(capakey.Gemeente, list_gemeente_adapter)
json_list_renderer.add_adapter(capakey.Afdeling, list_afdeling_adapter)
json_list_renderer.add_adapter(capakey.Sectie, list_sectie_adapter)
Expand All @@ -73,7 +75,8 @@ def item_gemeente_adapter(obj, request):
'id': obj.id,
'naam': obj.naam,
'centroid': obj.centroid,
'bounding_box': obj.bounding_box
'bounding_box': obj.bounding_box,
'shape': json.loads(obj.shape)
}


Expand All @@ -90,7 +93,8 @@ def item_afdeling_adapter(obj, request):
'naam': obj.gemeente.naam
},
'centroid': obj.centroid,
'bounding_box': obj.bounding_box
'bounding_box': obj.bounding_box,
'shape': json.loads(obj.shape)
}


Expand All @@ -110,7 +114,8 @@ def item_sectie_adapter(obj, request):
},
},
'centroid': obj.centroid,
'bounding_box': obj.bounding_box
'bounding_box': obj.bounding_box,
'shape': json.loads(obj.shape)
}


Expand All @@ -135,7 +140,8 @@ def item_perceel_adapter(obj, request):
'capakey': obj.capakey,
'percid': obj.percid,
'centroid': obj.centroid,
'bounding_box': obj.bounding_box
'bounding_box': obj.bounding_box,
'shape': json.loads(obj.shape)
}


Expand Down
32 changes: 20 additions & 12 deletions crabpy_pyramid/tests/renderers/test_capakey.py
Expand Up @@ -102,16 +102,16 @@ def test_list_secties(self):
def test_list_percelen(self):
percelen = [
Perceel(
'1154/02C000',
'1154/02C000',
Sectie(
'A',
'A',
Afdeling(
46013,
'KRUIBEKE 1 AFD/KRUIBEKE/',
Gemeente(46013, 'Kruibeke')
)
),
'46013A1154/02C000',
'46013A1154/02C000',
'46013_A_1154_C_000_02'
)
]
Expand Down Expand Up @@ -152,7 +152,8 @@ def test_item_gemeente(self):
44021,
'Gent',
(104154.2225, 197300.703),
(94653.453, 185680.984, 113654.992, 208920.422)
(94653.453, 185680.984, 113654.992, 208920.422),
'{"coordinates":[[[104040.42756348848,194680.14023317024],[104040.61297148466,194680.24852116778],[104040.7963314876,13317024]]],"type":"Polygon","crs":{"type":"link","properties":{"href":"http://www.opengis.net/def/crs/EPSG/0/31370"}}}'
)
dump = self.renderer(g, {})
self.assertEquals(
Expand All @@ -161,7 +162,8 @@ def test_item_gemeente(self):
'id': 44021,
'naam': 'Gent',
'centroid': [104154.2225, 197300.703],
'bounding_box': [94653.453, 185680.984, 113654.992, 208920.422]
'bounding_box': [94653.453, 185680.984, 113654.992, 208920.422],
'shape': {"coordinates":[[[104040.42756348848,194680.14023317024],[104040.61297148466,194680.24852116778],[104040.7963314876,13317024]]],"type":"Polygon","crs":{"type":"link","properties":{"href":"http://www.opengis.net/def/crs/EPSG/0/31370"}}}
}
)

Expand All @@ -171,7 +173,8 @@ def test_item_afdeling(self):
'GENT 1 AFD',
Gemeente(44021, 'Gent'),
(104893.06375, 196022.244094),
(104002.076625, 194168.3415, 105784.050875, 197876.146688)
(104002.076625, 194168.3415, 105784.050875, 197876.146688),
'{"coordinates":[[[104040.42756348848,194680.14023317024],[104040.61297148466,194680.24852116778],[104040.7963314876,13317024]]],"type":"Polygon","crs":{"type":"link","properties":{"href":"http://www.opengis.net/def/crs/EPSG/0/31370"}}}'
)
dump = self.renderer(a, {})
self.assertEquals(
Expand All @@ -184,7 +187,8 @@ def test_item_afdeling(self):
'naam': 'Gent'
},
'centroid': [104893.06375, 196022.244094],
'bounding_box': [104002.076625, 194168.3415, 105784.050875, 197876.146688]
'bounding_box': [104002.076625, 194168.3415, 105784.050875, 197876.146688],
'shape': {"coordinates":[[[104040.42756348848,194680.14023317024],[104040.61297148466,194680.24852116778],[104040.7963314876,13317024]]],"type":"Polygon","crs":{"type":"link","properties":{"href":"http://www.opengis.net/def/crs/EPSG/0/31370"}}}
}
)

Expand All @@ -193,7 +197,8 @@ def test_item_sectie(self):
'A',
Afdeling(44021, 'GENT 1 AFD', Gemeente(44021, 'Gent')),
(104893.06375, 196022.244094),
(104002.076625, 194168.3415, 105784.050875, 197876.146688)
(104002.076625, 194168.3415, 105784.050875, 197876.146688),
'{"coordinates":[[[104040.42756348848,194680.14023317024],[104040.61297148466,194680.24852116778],[104040.7963314876,13317024]]],"type":"Polygon","crs":{"type":"link","properties":{"href":"http://www.opengis.net/def/crs/EPSG/0/31370"}}}'
)
dump = self.renderer(s, {})
self.assertEquals(
Expand All @@ -209,13 +214,14 @@ def test_item_sectie(self):
},
},
'centroid': [104893.06375, 196022.244094],
'bounding_box': [104002.076625, 194168.3415, 105784.050875, 197876.146688]
'bounding_box': [104002.076625, 194168.3415, 105784.050875, 197876.146688],
'shape': {"coordinates":[[[104040.42756348848,194680.14023317024],[104040.61297148466,194680.24852116778],[104040.7963314876,13317024]]],"type":"Polygon","crs":{"type":"link","properties":{"href":"http://www.opengis.net/def/crs/EPSG/0/31370"}}}
}
)

def test_item_perceel(self):
p = Perceel(
'1154/02C000',
'1154/02C000',
Sectie(
'A',
Afdeling(
Expand All @@ -227,7 +233,8 @@ def test_item_perceel(self):
'40613A1154/02C000', '40613_A_1154_C_000_02',
'capaty', 'cashkey',
(104893.06375, 196022.244094),
(104002.076625, 194168.3415, 105784.050875, 197876.146688)
(104002.076625, 194168.3415, 105784.050875, 197876.146688),
'{"coordinates":[[[104040.42756348848,194680.14023317024],[104040.61297148466,194680.24852116778],[104040.7963314876,13317024]]],"type":"Polygon","crs":{"type":"link","properties":{"href":"http://www.opengis.net/def/crs/EPSG/0/31370"}}}'
)
dump = self.renderer(p, {})
self.assertEquals(
Expand All @@ -248,6 +255,7 @@ def test_item_perceel(self):
'capakey': '40613A1154/02C000',
'percid': '40613_A_1154_C_000_02',
'centroid': [104893.06375, 196022.244094],
'bounding_box': [104002.076625, 194168.3415, 105784.050875, 197876.146688]
'bounding_box': [104002.076625, 194168.3415, 105784.050875, 197876.146688],
'shape': {"coordinates":[[[104040.42756348848,194680.14023317024],[104040.61297148466,194680.24852116778],[104040.7963314876,13317024]]],"type":"Polygon","crs":{"type":"link","properties":{"href":"http://www.opengis.net/def/crs/EPSG/0/31370"}}}
}
)
4 changes: 2 additions & 2 deletions crabpy_pyramid/tests/test_capakey.py
Expand Up @@ -18,8 +18,8 @@
import unittest2 as unittest
except ImportError:
import unittest # noqa


class TestRegistry(object):

def __init__(self, settings=None):
Expand Down
5 changes: 5 additions & 0 deletions crabpy_pyramid/tests/test_functional.py
Expand Up @@ -143,6 +143,11 @@ def test_get_perceel_by_unexisting_sectie_and_id(self):
def test_get_perceel_by_capakey(self):
res = self.testapp.get('/capakey/percelen/11001B0001/00S000')
self.assertEqual('200 OK', res.status)
self.assertIn('shape', res.json)
self.assertIn('type', res.json['shape'])
self.assertIn('crs', res.json['shape'])
self.assertIn('coordinates', res.json['shape'])
self.assertGreater(len(res.json['shape']['coordinates']), 0)

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

0 comments on commit 37f8e9c

Please sign in to comment.