Example #1
0
def test_set_layer():
    """ test set_layer method """
    test_layer_name = "test"

    sfarcgis = SfArcgis()
    sfarcgis.set_layer(test_layer_name, TEST_ARCGIS_LAYER_URL)
    assert sfarcgis.gis_layers[test_layer_name] == TEST_ARCGIS_LAYER_URL
Example #2
0
    def parcels(self, req, resp):
        """ get parcels """

        missing_env = self.has_missing_env(['PLN_ARCGIS_PARCEL'])
        if missing_env:
            resp.status = falcon.HTTP_404
            msg_error = jsend.error(
                'Missing or invalid environment variable(s): ' +
                ", ".join(missing_env))
            resp.body = json.dumps(msg_error)
            return

        response = {'message': 'parcels'}
        if 'address' in req.params:
            address = req.params['address']
            options = {
                'returnGeometry': False,
                'returnSuggestions': False,
                'outFields': 'blklot,block_num,lot_num,ADDRESS'
            }
            if 'returnSuggestions' in req.params and req.params[
                    'returnSuggestions'] == 'true':
                options['returnSuggestions'] = True
            if 'returnGeometry' in req.params:
                options['returnGeometry'] = req.params['returnGeometry']
            if 'outFields' in req.params:
                options['outFields'] = req.params['outFields']

            sfarcgis = SfArcgis()
            sfarcgis.set_layer('parcel', os.environ.get('PLN_ARCGIS_PARCEL'))
            parcels = sfarcgis.get_fields_by_address(address, options)
            response = {'parcels': parcels}

            with sentry_sdk.configure_scope() as scope:
                scope.set_extra('arcgis.parcels', {
                    'address': address,
                    'options': options,
                    'response': parcels
                })

            blank_response_msg = ""
            if not parcels:
                blank_response_msg = "(blank)"

            sentry_sdk.capture_message(
                ('parcel response ' + blank_response_msg).strip(), 'info')

        resp.body = json.dumps(jsend.success(response))
        resp.status = falcon.HTTP_200
class Page():
    """ Page class """
    def __init__(self):
        self.sfarcgis = None

    def on_get(self, _req, _resp, name):
        """ on page GET requests """
        dispatch = None
        if hasattr(self.__class__, name) and callable(
                getattr(self.__class__, name)):
            dispatch = getattr(self, name)
            self.sfarcgis = SfArcgis()
        dispatch(_req, _resp)

    def get_fields_by_address_example(self, req, resp):
        """ example get_fields_by_address with an address response """

        self.sfarcgis.set_layer('parcel',
                                os.environ.get('PLN_ARCGIS_PARCEL_LAYER_URL'))

        if 'address' in req.params:
            address = req.params['address']
            options = {'returnGeometry': False, 'returnSuggestions': False}
            if 'returnSuggestions' in req.params and req.params[
                    'returnSuggestions'] == 'true':
                options['returnSuggestions'] = True
            if 'returnGeometry' in req.params:
                options['returnGeometry'] = req.params['returnGeometry']
            if 'outFields' in req.params:
                options['outFields'] = req.params['outFields']
            self.sfarcgis.set_layer(
                'parcel', os.environ.get('PLN_ARCGIS_PARCEL_LAYER_URL'))
            parcels = self.sfarcgis.get_fields_by_address(address, options)
            response = {'parcels': parcels}
        resp.body = json.dumps(jsend.success(response))
        resp.status = falcon.HTTP_200

    def get_fields_by_parcel_example(self, req, resp):
        """ example get_fields_by_parcel with an parcel number response """

        self.sfarcgis.set_layer('parcel',
                                os.environ.get('PLN_ARCGIS_PARCEL_LAYER_URL'))

        if 'parcel' in req.params:
            parcel = req.params['parcel']
            options = {'returnGeometry': False}
            if 'returnGeometry' in req.params:
                options['returnGeometry'] = req.params['returnGeometry']
            if 'outFields' in req.params:
                options['outFields'] = req.params['outFields']
            self.sfarcgis.set_layer(
                'parcel', os.environ.get('PLN_ARCGIS_PARCEL_LAYER_URL'))
            parcels = self.sfarcgis.get_fields_by_parcel(parcel, options)
            response = {'parcels': parcels}
        resp.body = json.dumps(jsend.success(response))
        resp.status = falcon.HTTP_200
Example #4
0
def test_get_fields_by_parcel():
    """ test get_fields_by_parcel method """
    with open('tests/mocks/parcel_request.json', 'r') as file_obj:
        mock_request = json.load(file_obj)

    with open('tests/mocks/parcel.json', 'r') as file_obj:
        mock_data = json.load(file_obj)

    sfarcgis = SfArcgis()
    sfarcgis.set_layer("parcel", TEST_ARCGIS_LAYER_URL)

    with patch('sf_arcgis_sdk.sf_arcgis.requests.get') as mock_get:
        mock_get.return_value.status_code = 200
        mock_get.return_value.json.return_value = mock_request
        options = {
            'outFields': 'blklot,block_num,lot_num,ADDRESS',
            'returnGeometry': 'false',
            'f': 'json'
        }
        parcel = sfarcgis.get_fields_by_parcel('3512008', options)
    assert parcel == mock_data