Skip to content

Commit

Permalink
test: service layer init
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdadams committed Jul 14, 2023
1 parent df3fbff commit 0700b45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 39 deletions.
18 changes: 2 additions & 16 deletions src/palletjack/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,20 +563,6 @@ class RESTServiceLoader:
in case of error to ensure the best chance of success.
"""

# @classmethod
# def get_feature_layers_info(cls, service_url, timeout=5):
# """Get the information dictionary for all the feature layers in the service

# Args:
# service_url (str): The base URL to the service's REST endpoint
# timeout (int, optional): Timeout value in seconds for HTML requests. Defaults to 5.

# Returns:
# _type_: _description_
# """
# service = cls(service_url=service_url, timeout=timeout)
# return service._get_feature_layers_info_from_service()

def __init__(self, service_url, timeout=5):
"""Create a representation of a REST FeatureService or MapService
Expand Down Expand Up @@ -647,14 +633,14 @@ def get_features(self, layer=0, chunk_size=100, envelope_params=None, feature_pa

return all_features_df


def get_feature_layers_info(self):
"""Get the information dictionary for any and all feature layers within the service.
Retries the request to the service's REST endpoint three times in case of error.
Raises:
RuntimeError: If the response can't be parsed as JSON, the service does not contain layers, or the response does not contain information about the layer types
RuntimeError: If the response can't be parsed as JSON, the service does not contain layers, or the response
does not contain information about the layer types
Returns:
dict: The parsed JSON info of the service's feature layers
Expand Down
33 changes: 10 additions & 23 deletions tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,25 +989,11 @@ def test_get_unique_id_list_as_dataframe_raises_on_len_mismatch(self, mocker):
extract._ServiceLayer.get_unique_id_list_as_dataframe(class_mock, 'OBJECTID', oid_list)

def test_init_builds_envelope_params(self, mocker):
test_loader = extract._ServiceLayer.__init__(
mocker.Mock(_get_layer_info=lambda: {'maxRecordCount': 8}),
mocker.Mock(),
42,
envelope_params={
'geometry': 'eggs',
'inSR': 'spam'
}
)
mocker.patch('palletjack.extract._ServiceLayer._get_layer_info', return_value={'maxRecordCount': 8})
mocker.patch('palletjack.extract._ServiceLayer._get_object_id_field')
mocker.patch('palletjack.extract._ServiceLayer._check_layer_type')

test_loader = extract._ServiceLayer(
mocker.Mock(_get_layer_info=lambda: {'maxRecordCount': 8}),
mocker.Mock(),
42,
envelope_params={
'geometry': 'eggs',
'inSR': 'spam'
}
)
test_loader = extract._ServiceLayer(mocker.Mock(), 42, envelope_params={'geometry': 'eggs', 'inSR': 'spam'})

assert test_loader.envelope_params == {
'geometryType': 'esriGeometryEnvelope',
Expand All @@ -1016,11 +1002,12 @@ def test_init_builds_envelope_params(self, mocker):
}

def test_init_builds_feature_params(self, mocker):
test_loader = extract._ServiceLayer.__init__(
mocker.Mock(_get_layer_info=lambda: {'maxRecordCount': 8}),
mocker.Mock(),
42,
feature_params={
mocker.patch('palletjack.extract._ServiceLayer._get_layer_info', return_value={'maxRecordCount': 8})
mocker.patch('palletjack.extract._ServiceLayer._get_object_id_field')
mocker.patch('palletjack.extract._ServiceLayer._check_layer_type')

test_loader = extract._ServiceLayer(
mocker.Mock(), 42, feature_params={
'where': 'eggs',
'returnGeometry': 'spam'
}
Expand Down

0 comments on commit 0700b45

Please sign in to comment.