-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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. | ||
|
@@ -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. | ||
|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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/', | ||
} | ||
} | ||
|
||
|
@@ -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' | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,9 @@ | |
|
||
# Constants | ||
URLS = { | ||
'test1': 'api/v2/test', | ||
'test2': 'api/v2/test2', | ||
'test3': 'api/v2/test3', | ||
'test1': 'api/v3/test', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
'test2': 'api/v3/test2', | ||
'test3': 'api/v3/test3', | ||
} | ||
|
||
CONFIG_DICT = { | ||
|
@@ -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 | ||
|
@@ -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 | ||
) | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 :)