Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Deprecated APIs, Fix Typos #23

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyseed/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ confidence=
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once).You can also use "--disable=all" to
# disable everything first and then reenable specific checks. For example, if
# disable everything first and then re-enable specific checks. For example, if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, this isn't even our code--nice, fixing typos for all :)

# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
Expand Down
22 changes: 11 additions & 11 deletions pyseed/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
copyright (c) 2016 Earth Advantage. All rights reserved.
..codeauthor::Paul Munday <[email protected]>

Functionality for calls to external API's"""
Functionality for calls to external APIs"""

# Imports from Third Party Modules
import re
Expand Down Expand Up @@ -47,15 +47,15 @@ def __init__(self, url=None, use_ssl=True, timeout=None, use_json=False,
# pylint: disable=too-many-arguments
"""Set url,api key, auth usage, ssl usage, timeout etc.

:param url: url to use, http(s)://can be omitted, an error will
will be used if it is supplied and dose not match use_ssl
:param: use_ssl: connect over https, defaults to true
:param url: url to use, http(s):// can be omitted, an error will
be used if it is supplied and does not match `use_ssl`
:param: use_ssl: connect over https, defaults to True
:param use_auth: use authentication

..Note:
if use_auth is True the default is to use http basic
If `use_auth` is True the default is to use http basic
authentication if self.auth is not set. (You will need to
to this by overriding __init__ and setting this before
do this by overriding __init__ and setting this before
calling super.

This requires username and password to be supplied as
Expand All @@ -64,7 +64,7 @@ def __init__(self, url=None, use_ssl=True, timeout=None, use_json=False,

To use Digest Authentication set auth_method='digest'

If use_ssl is False and the url you supply starts with https
If `use_ssl` is False and the url you supply starts with https
an error will be thrown.
"""
self.timeout = timeout
Expand All @@ -80,7 +80,7 @@ def __init__(self, url=None, use_ssl=True, timeout=None, use_json=False,
def _construct_payload(self, params):
"""Construct parameters for an api call.
.
:param params: An dictionary of key-value pairs to include
:param params: A dictionary of key-value pairs to include
in the request.
:return: A dictionary of k-v pairs to send to the server
in the request.
Expand Down Expand Up @@ -319,7 +319,7 @@ def _get_auth(self):
def _construct_payload(self, params):
"""Construct parameters for an api call.
.
:param params: An dictionary of key-value pairs to include
:param params: A dictionary of key-value pairs to include
in the request.
:return: A dictionary of k-v pairs to send to the server
in the request.
Expand Down Expand Up @@ -355,8 +355,8 @@ def _get_access_token(self):

def _construct_payload(self, params):
"""Construct parameters for an api call.
.
:param params: An dictionary of key-value pairs to include

:param params: A dictionary of key-value pairs to include
in the request.
:return: A dictionary of k-v pairs to send to the server
in the request.
Expand Down
16 changes: 8 additions & 8 deletions pyseed/seed_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(
# favor the connection params over the config file
self.payload = {}
if connection_params:
# the connetion params are simply squashed on SEEDReadWriteClient init
# the connection params are simply squashed on SEEDReadWriteClient init
self.payload = connection_params
elif connection_config_filepath:
self.payload = SeedClientWrapper.read_connection_config_file(
Expand Down Expand Up @@ -590,7 +590,7 @@ def get_or_create_cycle(
cycle_name = str(cycle_name)

# note that this picks the first one it finds, even if there are more
# than one cycle with the name name
# than one cycle with the same name
cycle_names = [cycle["name"] for cycle in cycles]
counts = Counter(cycle_names)
for i_cycle_name, count in counts.items():
Expand Down Expand Up @@ -824,7 +824,7 @@ def create_or_update_column_mapping_profile(
an already existing profile if it is there.

Args:
mapping_profile_name (str): cription_
mapping_profile_name (str): profile name
mappings (list): list of mappings in the form of
[
{
Expand Down Expand Up @@ -917,7 +917,7 @@ def set_import_file_column_mappings(
"""Sets the column mappings onto the import file record.

Args:
import_file_id (int): ID of the import file of interet
import_file_id (int): ID of the import file of interest
mappings (list): list of column mappings in the form of the results of column mapping profiles

Returns:
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def delete_meter(self, property_view_id: int, meter_id: int) -> dict:
meter_id (int): meter id

Returns:
dict: status of the delete
dict: status of the deletion
"""
return self.client.delete(
meter_id, endpoint='properties_meters', url_args={"PK": property_view_id}
Expand All @@ -1022,9 +1022,9 @@ def upsert_meter_readings_bulk(self, property_view_id: int, meter_id: int, data:
"""Upsert meter readings for a property's meter with the bulk method.

Args:
property_id (int): property id
property_view_id (int): property view id
meter_id (int): meter id
data (list): list of dictioanries of meter readings
data (list): list of dictionaries of meter readings

Returns:
dict: list of all meter reading objects
Expand Down Expand Up @@ -1184,7 +1184,7 @@ def check_meters_tab_exist(self, import_file_id: int) -> bool:
def import_files_reuse_inventory_file_for_meters(self, import_file_id: int) -> dict:
"""Reuse an import file to create all the meter entries. This method is used
for ESPM related data files. The result will be another import_file ID for the
meters that will then need to be "resaved". Note that the returning import_file_id
meters that will then need to be "re-saved". Note that the returning import_file_id
is not the same as the argument import file.

Args:
Expand Down
32 changes: 7 additions & 25 deletions pyseed/seed_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,13 @@
'import_files_start_matching_pk': '/api/v3/import_files/PK/start_system_matching_and_geocoding/',
'import_files_check_meters_tab_exists_pk': '/api/v3/import_files/PK/check_meters_tab_exists/',
'org_column_mapping_import_file': 'api/v3/organizations/ORG_ID/column_mappings/',
'properties_meters_reading': '/api/v3/properties/PK/meters/METER_PK/readings/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch on having this be in multiple places!

# GETs with replaceable keys
'import_files_matching_results': '/api/v3/import_files/PK/matching_and_geocoding_results/',
'progress': '/api/v3/progress/PROGRESS_KEY/',
'properties_meters': '/api/v3/properties/PK/meters/',
'properties_meter_usage': '/api/v3/properties/PK/meter_usage/',
# GET & POST with replaceable keys
'properties_meters_reading': '/api/v3/properties/PK/meters/METER_PK/readings/',
},
'v2': {
'columns': '/api/v2/columns/',
'column_mappings': '/api/v2/column_mappings/',
'cycles': '/api/v2/cycles/',
'datasets': '/api/v2/datasets/',
'gbr_properties': '/api/v2/gbr_properties/',
'green_assessment': '/api/v2/green_assessments/',
'green_assessment_property': '/api/v2/green_assessment_properties/',
'green_assessment_url': '/api/v2/green_assessment_urls/',
'labels': '/api/v2/labels/',
'import_files': '/api/v2/import_files/',
'projects': '/api/v2/projects/',
'properties': '/api/v2/properties/',
'property_states': '/api/v2/property_states/',
'property_views': '/api/v2/property_views/',
'taxlots': '/api/v2/taxlots/',
'users': '/api/v2/users/',
}
}

Expand Down Expand Up @@ -141,14 +123,14 @@ class SEEDBaseClient(JSONAPI):
can inherit from them directly and overwrite methods/use mixins as
appropriate.

endpoint refers to the endpoint name. This allow you to call an
endpoint refers to the endpoint name. This allows you to call an
endpoint without having to know the full url.

Endpoint names are set in config, and can be accessed as self.endpoints.

data_name is set as an attribute on the view called.
This constrains the actual response data.
If not set it is derived from the url (typically its the view name).
If not set it is derived from the url (typically it's the view name).
In either case 'data' is used as a fallback, then detail.

This is an annoyance, but SEED adds an unnecessary 'status'
Expand All @@ -162,7 +144,7 @@ class SEEDBaseClient(JSONAPI):
:type username: string (email address)
:param api_key: api_key of use who can access records
:type api_key: string
:param endpoint: seed endpoint e.g properties for /api/v2/properties/
:param endpoint: seed endpoint e.g. properties for /api/v3/properties/
:type endpoint: string
:param data_name: name of json key in api results containing data
not always needed
Expand Down Expand Up @@ -207,7 +189,7 @@ def _check_response(self, response, *args, **kwargs):
"""Verify we have got a response without any errors.

*Never* call this directly in your methods,
*Always use self._get() etc, otherwise errors will not
*Always use self._get() etc., otherwise errors will not
be reported correctly.
"""
error = False
Expand Down Expand Up @@ -315,14 +297,14 @@ def _raise_error(self, response, error_msg, stack_pos=0, *args, **kwargs):
"""
Raise SEEDError on bad response.

This method is intended for use only by self_get() etc and the methods
This method is intended for use only by self_get(), etc., and the methods
called there. For most purposes you should raise SEEDError directly.

This method uses the inspect module to derive the method name.
stack_pos indicates where in the stack to find this: it corresponds
to the depth of function calls.

Thus if the error occurs directly in the function calling _raise_error
Thus, if the error occurs directly in the function calling _raise_error
stack_pos=0, if that function is called by another function add 1 etc.
Note technically *this* method (_raise_error) is at the bottom of the
stack, but we add 1 to stack_pos so counting starts at the method
Expand Down
2 changes: 1 addition & 1 deletion tests/test_seed_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_get_column_mapping_profile(self):
result = self.seed_client.get_column_mapping_profile('does not exist')
assert result is None

# There should always be a portolio manager default unless the
# There should always be a portfolio manager default unless the
# user removed it.
result = self.seed_client.get_column_mapping_profile('Portfolio Manager Defaults')
assert isinstance(result, dict)
Expand Down
26 changes: 13 additions & 13 deletions tests/test_seed_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

# Constants
URLS = {
'test1': 'api/v2/test',
'test2': 'api/v2/test2',
'test3': 'api/v2/test3',
'test1': 'api/v3/test',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

'test2': 'api/v3/test2',
'test3': 'api/v3/test3',
}

CONFIG_DICT = {
Expand Down Expand Up @@ -135,13 +135,13 @@ def test_check_response_inheritance(self, mock_requests):
"""
Ensure errors are correctly reported.

SEEDError should show the calling method where the error occured.
SEEDError should show the calling method where the error occurred.
It uses the inspect module to get the calling method from the stack.

Error called in _check_response(), this also tests that method
as well as _raise_error().
"""
url = 'http://example.org/api/v2/test/'
url = 'http://example.org/api/v3/test/'
# Old SEED Style 200 (sic) with error message
mock_requests.get.return_value = get_mock_response(
data="No llama!", error=True
Expand Down Expand Up @@ -252,7 +252,7 @@ def setUp(self):

def test_delete(self, mock_requests):
# pylint:disable=no-member
url = 'https://example.org:1337/api/v2/test/1/'
url = 'https://example.org:1337/api/v3/test/1/'
mock_requests.delete.return_value = get_mock_response(
status_code=requests.codes.no_content
)
Expand All @@ -261,21 +261,21 @@ def test_delete(self, mock_requests):
mock_requests.delete.assert_called_with(url, **self.call_dict)

def test_get(self, mock_requests):
url = 'https://example.org:1337/api/v2/test/1/'
url = 'https://example.org:1337/api/v3/test/1/'
mock_requests.get.return_value = get_mock_response(data="Llama!")
result = self.client.get(1, endpoint='test1')
self.assertEqual('Llama!', result)
mock_requests.get.assert_called_with(url, **self.call_dict)

def test_list(self, mock_requests):
url = 'https://example.org:1337/api/v2/test/'
url = 'https://example.org:1337/api/v3/test/'
mock_requests.get.return_value = get_mock_response(data=["Llama!"])
result = self.client.list(endpoint='test1')
self.assertEqual(['Llama!'], result)
mock_requests.get.assert_called_with(url, **self.call_dict)

def test_patch(self, mock_requests):
url = 'https://example.org:1337/api/v2/test/1/'
url = 'https://example.org:1337/api/v3/test/1/'
mock_requests.patch.return_value = get_mock_response(data="Llama!")
result = self.client.patch(1, endpoint='test1', foo='bar', json={'more': 'data'})
self.assertEqual('Llama!', result)
Expand All @@ -292,7 +292,7 @@ def test_patch(self, mock_requests):
mock_requests.patch.assert_called_with(url, **expected)

def test_put(self, mock_requests):
url = 'https://example.org:1337/api/v2/test/1/'
url = 'https://example.org:1337/api/v3/test/1/'
mock_requests.put.return_value = get_mock_response(data="Llama!")
result = self.client.put(1, endpoint='test1', foo='bar', json={'more': 'data'})
self.assertEqual('Llama!', result)
Expand All @@ -309,7 +309,7 @@ def test_put(self, mock_requests):
mock_requests.put.assert_called_with(url, **expected)

def test_post(self, mock_requests):
url = 'https://example.org:1337/api/v2/test/'
url = 'https://example.org:1337/api/v3/test/'
mock_requests.post.return_value = get_mock_response(data="Llama!")
result = self.client.post(endpoint='test1', json={'foo': 'bar', 'not_org': 1})
self.assertEqual('Llama!', result)
Expand Down Expand Up @@ -347,13 +347,13 @@ def setUp(self):
}

def test_get(self, mock_requests):
# url = 'https://example.org:1337/api/v2/test/1/'
# url = 'https://example.org:1337/api/v3/test/1/'
mock_requests.get.return_value = get_mock_response(data="Llama!")
result = self.client.get(1, endpoint='test1')
self.assertEqual('Llama!', result)

def test_list(self, mock_requests):
# url = 'https://example.org:1337/api/v2/test/'
# url = 'https://example.org:1337/api/v3/test/'
mock_requests.get.return_value = get_mock_response(data=["Llama!"])
result = self.client.list(endpoint='test1')
self.assertEqual(['Llama!'], result)