Skip to content

Commit

Permalink
Merge pull request #125 from OnroerendErfgoed/DEV_0.12.0
Browse files Browse the repository at this point in the history
Dev 0.12.0
  • Loading branch information
claeyswo committed Jun 25, 2019
2 parents 6781035 + 28f6860 commit e47ea98
Show file tree
Hide file tree
Showing 19 changed files with 22,402 additions and 1,053 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ dogpile_data

# Rope
.ropeproject

# Pycharm
.idea/
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.12.0 (24-06-2019)
-------------------

- Switchen naar v2 van de capakey REST-API (#120)
- Mocken van calls naar externe url's bij testen (#118)
- get_perceel_by_coordinates (#121)

0.11.0 (03-01-2019)
------------------

Expand Down
8 changes: 5 additions & 3 deletions crabpy/gateway/capakey.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CapakeyRestGateway(object):
def __init__(self, **kwargs):
self.base_url = kwargs.get(
'base_url',
'https://geoservices.informatievlaanderen.be/capakey/api/v1'
'https://geoservices.informatievlaanderen.be/capakey/api/v2'
)
self.base_headers = {
'Accept': 'application/json'
Expand Down Expand Up @@ -383,7 +383,8 @@ def creator():
url = self.base_url + '/municipality/%s/department/%s/section/%s/parcel' % (gid, aid, sid)
h = self.base_headers
p = {
'data': 'adp'
'data': 'adp',
'status': 'actual'
}
res = capakey_rest_gateway_request(url, h, p).json()
return [
Expand Down Expand Up @@ -424,7 +425,8 @@ def creator():
p = {
'geometry': 'full',
'srs': '31370',
'data': 'adp'
'data': 'adp',
'status': 'actual'
}
res = capakey_rest_gateway_request(url, h, p).json()
return Perceel(
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pytest-cov==2.5.1
coveralls==1.3.0
flake8==3.5.0
mock==2.0.0
responses==0.10.6
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setup(
name='crabpy',
version='0.11.0',
version='0.12.0',
description='Interact with geographical webservices by Informatie Vlaanderen.',
long_description=open('README.rst').read() + '\n\n' +
open('CHANGES.rst').read(),
Expand Down
170 changes: 170 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# -*- coding: utf-8 -*
import json
import os
import re

import pytest
import responses
from mock import Mock

from crabpy.gateway.crab import CrabGateway

CAPAKEY_URL = 'https://geoservices.informatievlaanderen.be/capakey/api/v2'


def pytest_addoption(parser):
Expand All @@ -14,8 +24,168 @@ def pytest_addoption(parser):
help="capakey-integration: Run CAPAKEY integration tests or not?"
)


def load_json(filename):
current_dir = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(current_dir, 'dummy_responses', filename)) as file:
return json.load(file)


@pytest.fixture(scope="module")
def capakey_rest_gateway():
from crabpy.gateway.capakey import CapakeyRestGateway
capakey_gateway = CapakeyRestGateway()
return capakey_gateway


@pytest.fixture(scope='function')
def crab_service(crab_client_mock):
return crab_client_mock.service


@pytest.fixture(scope='function')
def crab_client_mock():
crab_client = Mock()
crab_client.service.ListBewerkingen.return_value = Mock(
CodeItem=[Mock(Code=1)]
)
crab_client.service.ListOrganisaties.return_value = Mock(
CodeItem=[Mock(Code=1)]
)
return crab_client


@pytest.fixture(scope='function')
def crab_gateway(crab_client_mock):
return CrabGateway(crab_client_mock)


@pytest.fixture(scope='function')
def mocked_responses():
with responses.RequestsMock() as rsps:
yield rsps


@pytest.fixture(scope='function')
def municipalities_response(mocked_responses):
mocked_responses.add(
method='GET',
url='{capakey}/municipality?'.format(capakey=CAPAKEY_URL),
json=load_json('municipalities.json')
)


@pytest.fixture(scope='function')
def municipality_response(mocked_responses):
url = re.compile(
r'{capakey}/municipality/\d+\?'.format(capakey=CAPAKEY_URL)
)
mocked_responses.add(
method='GET',
url=url,
json=load_json('municipality.json')
)


@pytest.fixture(scope='function')
def municipality_department_response(mocked_responses):
url = re.compile(
r'{capakey}/municipality/\d+/department\?'
.format(capakey=CAPAKEY_URL)
)
mocked_responses.add(
method='GET',
url=url,
json=load_json('municipality_department.json')
)


@pytest.fixture(scope='function')
def department_response(mocked_responses):
url = re.compile(
r'{capakey}/department/\d+\?'.format(capakey=CAPAKEY_URL)
)
mocked_responses.add(
method='GET',
url=url,
json=load_json('department.json')
)


@pytest.fixture(scope='function')
def department_sections_response(mocked_responses):
url = re.compile(
r'{capakey}/municipality/\d+/department/\d+/section$'
.format(capakey=CAPAKEY_URL)
)
mocked_responses.add(
method='GET',
url=url,
json=load_json('department_sections.json')
)


@pytest.fixture(scope='function')
def department_section_response(mocked_responses):
url = re.compile(
r'{capakey}/municipality/\d+/department/\d+/section/[^/]+\?'
.format(capakey=CAPAKEY_URL)
)
mocked_responses.add(
method='GET',
url=url,
json=load_json('department_section.json')
)


@pytest.fixture(scope='function')
def department_section_parcels_response(mocked_responses):
url = re.compile(
r'{capakey}/municipality/\d+/department/\d+/section/[^/]+/parcel\?'
.format(capakey=CAPAKEY_URL)
)
mocked_responses.add(
method='GET',
url=url,
json=load_json('department_section_parcels.json')
)


@pytest.fixture(scope='function')
def department_section_parcel_response(mocked_responses):
url = re.compile(
r'{capakey}/municipality/\d+/department/\d+/section/[^/]+/parcel/'
r'\d+/[^/]+\?'
.format(capakey=CAPAKEY_URL)
)
mocked_responses.add(
method='GET',
url=url,
json=load_json('department_section_parcel.json')
)


@pytest.fixture(scope='function')
def parcel_response(mocked_responses):
url = re.compile(
r'{capakey}/parcel/[^/]+/[^/]+\?'
.format(capakey=CAPAKEY_URL)
)
mocked_responses.add(
method='GET',
url=url,
json=load_json('parcel.json')
)


@pytest.fixture(scope='function')
def parcels_response(mocked_responses):
url = re.compile(
r'{capakey}/parcel\?'
.format(capakey=CAPAKEY_URL)
)
mocked_responses.add(
method='GET',
url=url,
json=load_json('parcel.json')
)
17 changes: 17 additions & 0 deletions tests/dummy_responses/department.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions tests/dummy_responses/department_section.json

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions tests/dummy_responses/department_section_parcel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"municipalityCode": "44021",
"municipalityName": "Gent",
"departmentCode": "44021",
"departmentName": "GENT 1 AFD",
"sectionCode": "A",
"perceelnummer": "0001/00A000",
"capakey": "44021A0001/00A000",
"grondnummer": "1",
"exponent": "A",
"macht": "000",
"bisnummer": "00",
"adres": [
"Opgeëistenlaan 2A, 9000 Gent"
],
"geometry": {
"boundingBox": "{\"coordinates\":[[[104029.2602000013,194665.02360000089],[104042.87200000137,194665.02360000089],[104042.87200000137,194688.71620000154],[104029.2602000013,194688.71620000154],[104029.2602000013,194665.02360000089]]],\"type\":\"Polygon\",\"crs\":{\"type\":\"link\",\"properties\":{\"href\":\"http://www.opengis.net/def/crs/EPSG/0/31370\"}}}",
"center": "{\"coordinates\":[104036.06610000134,194676.86990000121],\"type\":\"Point\",\"crs\":{\"type\":\"link\",\"properties\":{\"href\":\"http://www.opengis.net/def/crs/EPSG/0/31370\"}}}",
"shape": "{\"coordinates\":[[[104040.42759999633,194680.14020000026],[104040.61299999803,194680.24850000069],[104040.79630000144,194680.35909999907],[104040.97600000352,194680.47430000082],[104041.1502000019,194680.59629999846],[104041.31679999828,194680.7276000008],[104041.46620000154,194680.86149999872],[104041.60769999772,194681.00450000167],[104041.74239999801,194681.15509999916],[104041.87060000002,194681.31190000102],[104041.99289999902,194681.47399999946],[104042.05759999901,194681.56599999964],[104042.11540000141,194681.64820000157],[104042.23080000281,194681.82679999992],[104042.33780000359,194682.00989999995],[104042.43450000137,194682.19779999927],[104042.51979999989,194682.39059999958],[104042.57940000296,194682.54969999939],[104042.63239999861,194682.71139999852],[104042.68020000309,194682.87510000169],[104042.7247999981,194683.04019999877],[104042.7677000016,194683.20600000024],[104042.81099999696,194683.43930000067],[104042.85119999945,194683.72329999879],[104042.87200000137,194684.36620000005],[104042.79349999875,194685.08669999987],[104042.58089999855,194685.82559999824],[104042.16870000213,194686.6325000003],[104041.82140000165,194687.1035999991],[104041.78050000221,194687.15900000185],[104041.76730000228,194687.17060000077],[104041.44740000367,194687.44949999824],[104040.98960000277,194687.75470000133],[104040.52690000087,194688.04360000044],[104040.05430000275,194688.29980000108],[104039.56639999896,194688.50719999894],[104039.39919999987,194688.5540000014],[104039.05870000273,194688.64930000156],[104038.77049999684,194688.69420000166],[104038.47720000148,194688.71609999985],[104038.18150000274,194688.71620000154],[104037.88539999723,194688.69590000063],[104037.59210000187,194688.65670000017],[104037.3227000013,194688.60399999842],[104037.05759999901,194688.53610000014],[104036.7968999967,194688.45320000127],[104036.54089999944,194688.35509999841],[104036.28930000216,194688.24199999869],[104035.89429999888,194688.02809999883],[104035.51940000057,194687.7771999985],[104035.17279999703,194687.49179999903],[104034.86240000278,194687.17370000109],[104034.59610000253,194686.82519999892],[104034.33900000155,194686.36549999937],[104034.14329999685,194685.87269999832],[104033.99350000173,194685.35480000079],[104033.87470000237,194684.82039999962],[104033.77090000361,194684.27769999951],[104033.87910000235,194683.46110000089],[104033.89580000192,194683.40309999883],[104034.05569999665,194682.8451000005],[104034.15139999986,194682.51080000028],[104034.59019999951,194681.67550000176],[104034.98189999908,194681.18730000034],[104035.0869999975,194681.05620000139],[104035.50760000199,194680.71389999986],[104035.92000000179,194680.37829999998],[104036.57710000128,194680.03669999912],[104036.8348999992,194679.9439000003],[104034.72699999809,194674.03049999848],[104034.33799999952,194674.061999999],[104033.94990000129,194674.08309999853],[104033.56430000067,194674.08940000087],[104033.18219999969,194674.07149999961],[104032.80479999632,194674.02129999921],[104032.56170000136,194673.96790000051],[104032.32150000334,194673.89840000123],[104032.08449999988,194673.814100001],[104031.85119999945,194673.71590000018],[104031.62189999968,194673.60509999841],[104031.24870000035,194673.39319999889],[104030.89479999989,194673.15029999986],[104030.61249999702,194672.9151000008],[104030.5671999976,194672.87739999965],[104030.27290000021,194672.57620000094],[104030.01889999956,194672.2478],[104029.73139999807,194671.73169999942],[104029.61869999766,194671.43090000004],[104029.58500000089,194671.34090000018],[104029.52220000327,194671.17289999872],[104029.37160000205,194670.5821999982],[104029.31809999794,194670.28880000114],[104029.28549999744,194670.10960000008],[104029.2602000013,194669.97019999847],[104029.31530000269,194668.83769999817],[104029.44940000027,194668.20650000125],[104029.54190000147,194667.97610000148],[104029.71209999919,194667.55299999937],[104029.86400000006,194667.30519999936],[104030.0046999976,194667.07569999993],[104030.39590000361,194666.57290000096],[104030.96029999852,194666.01429999992],[104031.54330000281,194665.6398999989],[104031.95470000058,194665.47709999979],[104032.05759999901,194665.43899999931],[104032.36770000309,194665.32459999993],[104032.78390000015,194665.19319999963],[104033.20499999821,194665.09310000017],[104033.44160000235,194665.06260000169],[104033.63289999962,194665.0346999988],[104033.93429999799,194665.02360000089],[104034.23740000278,194665.03649999946],[104034.53989999741,194665.0727000013],[104034.83950000256,194665.13100000098],[104035.13400000334,194665.21029999852],[104035.38229999691,194665.2949000001],[104035.40999999642,194665.30620000139],[104035.62439999729,194665.39389999956],[104035.67010000348,194665.41580000147],[104035.8601000011,194665.50679999962],[104036.08860000223,194665.63309999928],[104036.30969999731,194665.77250000089],[104036.51950000226,194665.92190000042],[104036.72079999745,194666.08289999887],[104036.9123999998,194666.25519999862],[104037.09350000322,194666.438000001],[104037.26330000162,194666.63109999895],[104037.43630000204,194666.85509999841],[104037.59449999779,194667.08999999985],[104037.73809999973,194667.33469999954],[104037.86710000038,194667.58830000088],[104037.98170000315,194667.84980000183],[104038.0842999965,194668.12620000169],[104038.16960000247,194668.40810000151],[104038.23560000211,194668.69409999996],[104038.28000000119,194668.98209999874],[104038.30080000311,194669.27059999853],[104038.28249999881,194669.73519999906],[104038.27220000327,194669.80119999871],[104038.21019999683,194670.19720000029],[104038.09749999642,194670.65720000118],[104037.95750000328,194671.11569999903],[104037.80420000106,194671.5736999996],[104039.26619999856,194672.42639999837],[104039.3770999983,194672.39530000091],[104041.26079999655,194678.33650000021],[104040.9843999967,194678.42410000041],[104040.42759999633,194680.14020000026]]],\"type\":\"Polygon\",\"crs\":{\"type\":\"link\",\"properties\":{\"href\":\"http://www.opengis.net/def/crs/EPSG/0/31370\"}}}"
},
"result": {
"succes": true,
"startTimeStamp": "2019-06-18T07:06:47.1052597+00:00",
"endTimeStamp": "2019-06-18T07:06:47.1052597+00:00",
"elapsed": 0
}
}
Loading

0 comments on commit e47ea98

Please sign in to comment.