From 0700b45072726d5c36cb8cdd4e9d5851d3c5104b Mon Sep 17 00:00:00 2001 From: Jake Adams Date: Fri, 14 Jul 2023 10:24:34 -0600 Subject: [PATCH] test: service layer init --- src/palletjack/extract.py | 18 ++---------------- tests/test_extract.py | 33 ++++++++++----------------------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/src/palletjack/extract.py b/src/palletjack/extract.py index b2adb45..cfafbe1 100644 --- a/src/palletjack/extract.py +++ b/src/palletjack/extract.py @@ -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 @@ -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 diff --git a/tests/test_extract.py b/tests/test_extract.py index 41372b1..c1869f0 100644 --- a/tests/test_extract.py +++ b/tests/test_extract.py @@ -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', @@ -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' }