# Path: tests/conftest.py
# CAPAKEY_URL = 'https://geoservices.informatievlaanderen.be/capakey/api/v2'
# 
# Path: crabpy/gateway/capakey.py
# def capakey_rest_gateway_request(url, headers={}, params={}):
#     def __init__(self, **kwargs):
#     def _parse_centroid(center):
#     def _parse_bounding_box(bounding_box):
#     def list_gemeenten(self, sort=1):
#         def creator():
#     def get_gemeente_by_id(self, id):
#         def creator():
#     def list_kadastrale_afdelingen(self):
#         def creator():
#     def list_kadastrale_afdelingen_by_gemeente(self, gemeente, sort=1):
#         def creator():
#     def get_kadastrale_afdeling_by_id(self, aid):
#         def creator():
#     def list_secties_by_afdeling(self, afdeling):
#         def creator():
#     def get_sectie_by_id_and_afdeling(self, id, afdeling):
#         def creator():
#     def parse_percid(self, capakey):
#     def parse_capakey(self, percid):
#     def list_percelen_by_sectie(self, sectie):
#         def creator():
#     def get_perceel_by_id_and_sectie(self, id, sectie):
#         def creator():
#     def _get_perceel_by(self, url, cache_key):
#         def creator():
#     def get_perceel_by_capakey(self, capakey):
#     def get_perceel_by_coordinates(self, x, y):
#     def get_perceel_by_percid(self, percid):
#     def __init__(self, **kwargs):
#     def set_gateway(self, gateway):
#     def clear_gateway(self):
#     def check_gateway(self):
#     def __str__(self):
# def check_lazy_load_gemeente(f):
#     def wrapper(self):
#     def __init__(
#         self, id, naam=None,
#         centroid=None, bounding_box=None,
#         shape=None, **kwargs
#     ):
#     def naam(self):
#     def centroid(self):
#     def bounding_box(self):
#     def afdelingen(self):
#     def __unicode__(self):
#     def __repr__(self):
# def check_lazy_load_afdeling(f):
#     def wrapper(self):
#     def __init__(
#         self, id, naam=None, gemeente=None,
#         centroid=None, bounding_box=None,
#         shape=None, **kwargs
#     ):
#     def set_gateway(self, gateway):
#     def clear_gateway(self):
#     def naam(self):
#     def gemeente(self):
#     def centroid(self):
#     def bounding_box(self):
#     def secties(self):
#     def __unicode__(self):
#     def __repr__(self):
# def check_lazy_load_sectie(f):
#     def wrapper(self):
#     def __init__(
#         self, id, afdeling,
#         centroid=None, bounding_box=None,
#         shape=None, **kwargs
#     ):
#     def set_gateway(self, gateway):
#     def clear_gateway(self):
#     def centroid(self):
#     def bounding_box(self):
#     def percelen(self):
#     def __unicode__(self):
#     def __repr__(self):
# def check_lazy_load_perceel(f):
#     def wrapper(self):
#     def __init__(
#         self, id, sectie, capakey, percid, adres=None,
#         capatype=None, cashkey=None,
#         centroid=None, bounding_box=None,
#         shape=None, **kwargs
#     ):
#     def set_gateway(self, gateway):
#     def clear_gateway(self):
#     def get_percid_from_capakey(capakey):
#     def get_capakey_from_percid(percid):
#     def _split_capakey(self):
#     def centroid(self):
#     def bounding_box(self):
#     def capatype(self):
#     def cashkey(self):
#     def __unicode__(self):
#     def __repr__(self):
# class CapakeyRestGateway:
# class GatewayObject:
# class Gemeente(GatewayObject):
# class Afdeling(GatewayObject):
# class Sectie(GatewayObject):
# class Perceel(GatewayObject):


import re
    import unittest2 as unittest
    import unittest  # noqa
import pytest
import requests
from tests.conftest import CAPAKEY_URL
from crabpy.gateway.capakey import (
    Gemeente,
    Afdeling,
    Sectie,
    Perceel,
    capakey_rest_gateway_request,
    GatewayRuntimeException
)
    from unittest.mock import MagicMock, patch
    from unittest.mock import MagicMock, patch
        from crabpy.gateway.exception import GatewayResourceNotFoundException
                                   department_response,
                                   department_section_response,
                                   department_section_parcels_response,
                                   parcel_response):
        s = capakey_rest_gateway.get_sectie_by_id_and_afdeling('A', 44021)
        percelen = capakey_rest_gateway.list_percelen_by_sectie(s)
        perc = percelen[0]
        res = capakey_rest_gateway.get_perceel_by_percid(perc.percid)
        assert isinstance(res, Perceel)
        assert res.sectie.id == 'A'
        assert res.sectie.afdeling.id == 44021

    @patch('requests.get', MagicMock(side_effect=connection_error))
    def test_requests_connection(self):
        with pytest.raises(GatewayRuntimeException) as cm:
            capakey_rest_gateway_request('url')
        exception = cm.value.message
        assert exception == 'Could not execute request due to connection problems:\nConnectionError()'

    @patch('requests.get', MagicMock(side_effect=request_exception))
    def test_requests_request_exception(self):
        with pytest.raises(GatewayRuntimeException) as cm:
            capakey_rest_gateway_request('url')
        exception = cm.value.message
        assert exception == 'Could not execute request due to:\nRequestException()'


class TestGemeente:

    def test_fully_initialised(self):

# Path: tests/conftest.py
# CAPAKEY_URL = 'https://geoservices.informatievlaanderen.be/capakey/api/v2'
# 
# Path: crabpy/gateway/capakey.py
# def capakey_rest_gateway_request(url, headers={}, params={}):
#     def __init__(self, **kwargs):
#     def _parse_centroid(center):
#     def _parse_bounding_box(bounding_box):
#     def list_gemeenten(self, sort=1):
#         def creator():
#     def get_gemeente_by_id(self, id):
#         def creator():
#     def list_kadastrale_afdelingen(self):
#         def creator():
#     def list_kadastrale_afdelingen_by_gemeente(self, gemeente, sort=1):
#         def creator():
#     def get_kadastrale_afdeling_by_id(self, aid):
#         def creator():
#     def list_secties_by_afdeling(self, afdeling):
#         def creator():
#     def get_sectie_by_id_and_afdeling(self, id, afdeling):
#         def creator():
#     def parse_percid(self, capakey):
#     def parse_capakey(self, percid):
#     def list_percelen_by_sectie(self, sectie):
#         def creator():
#     def get_perceel_by_id_and_sectie(self, id, sectie):
#         def creator():
#     def _get_perceel_by(self, url, cache_key):
#         def creator():
#     def get_perceel_by_capakey(self, capakey):
#     def get_perceel_by_coordinates(self, x, y):
#     def get_perceel_by_percid(self, percid):
#     def __init__(self, **kwargs):
#     def set_gateway(self, gateway):
#     def clear_gateway(self):
#     def check_gateway(self):
#     def __str__(self):
# def check_lazy_load_gemeente(f):
#     def wrapper(self):
#     def __init__(
#         self, id, naam=None,
#         centroid=None, bounding_box=None,
#         shape=None, **kwargs
#     ):
#     def naam(self):
#     def centroid(self):
#     def bounding_box(self):
#     def afdelingen(self):
#     def __unicode__(self):
#     def __repr__(self):
# def check_lazy_load_afdeling(f):
#     def wrapper(self):
#     def __init__(
#         self, id, naam=None, gemeente=None,
#         centroid=None, bounding_box=None,
#         shape=None, **kwargs
#     ):
#     def set_gateway(self, gateway):
#     def clear_gateway(self):
#     def naam(self):
#     def gemeente(self):
#     def centroid(self):
#     def bounding_box(self):
#     def secties(self):
#     def __unicode__(self):
#     def __repr__(self):
# def check_lazy_load_sectie(f):
#     def wrapper(self):
#     def __init__(
#         self, id, afdeling,
#         centroid=None, bounding_box=None,
#         shape=None, **kwargs
#     ):
#     def set_gateway(self, gateway):
#     def clear_gateway(self):
#     def centroid(self):
#     def bounding_box(self):
#     def percelen(self):
#     def __unicode__(self):
#     def __repr__(self):
# def check_lazy_load_perceel(f):
#     def wrapper(self):
#     def __init__(
#         self, id, sectie, capakey, percid, adres=None,
#         capatype=None, cashkey=None,
#         centroid=None, bounding_box=None,
#         shape=None, **kwargs
#     ):
#     def set_gateway(self, gateway):
#     def clear_gateway(self):
#     def get_percid_from_capakey(capakey):
#     def get_capakey_from_percid(percid):
#     def _split_capakey(self):
#     def centroid(self):
#     def bounding_box(self):
#     def capatype(self):
#     def cashkey(self):
#     def __unicode__(self):
#     def __repr__(self):
# class CapakeyRestGateway:
# class GatewayObject:
# class Gemeente(GatewayObject):
# class Afdeling(GatewayObject):
# class Sectie(GatewayObject):
# class Perceel(GatewayObject):


# Path: tests/gateway/test_capakey.py
import re
    import unittest2 as unittest
    import unittest  # noqa
import pytest
import requests
from tests.conftest import CAPAKEY_URL
from crabpy.gateway.capakey import (
    Gemeente,
    Afdeling,
    Sectie,
    Perceel,
    capakey_rest_gateway_request,
    GatewayRuntimeException
)
    from unittest.mock import MagicMock, patch
    from unittest.mock import MagicMock, patch
        from crabpy.gateway.exception import GatewayResourceNotFoundException

                                   department_response,
                                   department_section_response,
                                   department_section_parcels_response,
                                   parcel_response):
        s = capakey_rest_gateway.get_sectie_by_id_and_afdeling('A', 44021)
        percelen = capakey_rest_gateway.list_percelen_by_sectie(s)
        perc = percelen[0]
        res = capakey_rest_gateway.get_perceel_by_percid(perc.percid)
        assert isinstance(res, Perceel)
        assert res.sectie.id == 'A'
        assert res.sectie.afdeling.id == 44021

    @patch('requests.get', MagicMock(side_effect=connection_error))
    def test_requests_connection(self):
        with pytest.raises(GatewayRuntimeException) as cm:
            capakey_rest_gateway_request('url')
        exception = cm.value.message
        assert exception == 'Could not execute request due to connection problems:\nConnectionError()'

    @patch('requests.get', MagicMock(side_effect=request_exception))
    def test_requests_request_exception(self):
        with pytest.raises(GatewayRuntimeException) as cm:
            capakey_rest_gateway_request('url')
        exception = cm.value.message
        assert exception == 'Could not execute request due to:\nRequestException()'


class TestGemeente:

    def test_fully_initialised(self):

        g = Gemeente(