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

BES API Client #1

Merged
merged 8 commits into from
Jun 15, 2017
Merged

BES API Client #1

merged 8 commits into from
Jun 15, 2017

Conversation

tallus
Copy link

@tallus tallus commented May 8, 2017

- client for accessing the BES  API v1 & v2
- tests

Paul Munday added 2 commits February 24, 2017 16:17
    - client for accessing the BES  API v1 & v2
    - tests
@tallus tallus requested a review from fablet May 9, 2017 22:22
Copy link
Contributor

@fablet fablet left a comment

Choose a reason for hiding this comment

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

The only py3 issues I can across were the basestring problem we talked about and two uses of iteritems, both noted in line comments. If those changes are made then all tests, other than the one noted problem test, pass in py 2.7, 3.4, 3.5 and 3.6. I have a tox setup and ready to add if you want.
Pylint flags several whitespace errors, but it looks like most of the remaining pylint issues are by choice and may benefit from local overrides.

# Imports from External Modules
import requests

# Config/Constants
Copy link
Contributor

Choose a reason for hiding this comment

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

I like your sys.version_info approach to the basestring, py3, compatibility issue, but what about simplifying it further to:

PY3 = sys.version_info[0] == 3
if PY3:
    basestring = str

self.client._check_call_success(mock_response, prefix='Test')
error = conm.exception
self.assertEqual(
error.message, 'Test: 404 test: error, error: test'
Copy link
Contributor

Choose a reason for hiding this comment

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

this test is problematic. It passes sometimes and fails others. I believe it is because sometimes the error message is
'Test: 404 test: error, error: test' and other times it is 'Test: 404 error: test, test: error' since the portion of the message after '404' is constructed from an unordered dict

Copy link
Author

Choose a reason for hiding this comment

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

fixed

pybes/pybes.py Outdated
# Private Functions and Classes
def _fix_params(params):
"""For v1 api -- True is True but False is a string"""
for key, val in params.iteritems():
Copy link
Contributor

Choose a reason for hiding this comment

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

so far, the iteritems calls seem to be the only other py3 incompatibility I have found. We can run the 2to3 migration tool if you like, but since you only have this in two place, plus one mention in a docstring, they could just manually be changed to

iter(parms.items())

Copy link
Author

Choose a reason for hiding this comment

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

using items is probably sufficient here

pybes/pybes.py Outdated
)
raise BESError(msg)
return {
key: val for key, val in dct.iteritems()
Copy link
Contributor

Choose a reason for hiding this comment

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

the other iteritems() usage. see above.

iter(dct.items())

pybes/pybes.py Outdated
Set up Client:

Note for everything except setting up a user you will need to supply
email, password and organization_token in order to authenticate.
Copy link
Contributor

Choose a reason for hiding this comment

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

While I can see you are implementing this correctly, this docstring reads as counter to BES documentation which states that the the organization_token is only used for creating a user and getting an access token for that user, from which point it is the access token that you need

Copy link
Author

Choose a reason for hiding this comment

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

I added the ability to reuse tokens later as api calls are rate limiteds, I will update the docs accordingly.

pybes/pybes.py Outdated
:type float:
:param dimension_2: required Length of dimension 2 (in feet).
:type float:
:param /dimension_3: optional Length of dimension 3 (in feet).
Copy link
Contributor

Choose a reason for hiding this comment

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

there is a '/' character in front of the 'dimension_3' param name. also several param :type : blocks in this docstring need to have the the param name added, as in

:type vertices: str 

rather than

:type str:

pybes/pybes.py Outdated
:type bool:

:rtype: None
:raises: BES/APIError
Copy link
Contributor

Choose a reason for hiding this comment

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

repeat of docstring notes from previous method

pybes/pybes.py Outdated
For convienience block_resources e.g. air_handler, 'air handler'
will be converted (ie. spaces will be converted to underscores
and the value will be converted to lower case and pluralized
if needed). block_ at the beginning may be ommited
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in convenience and omitted
in param list, typo in resource_id in name block and in kwargs in type block.
should :name and :rname be :type and :rtype?

pybes/pybes.py Outdated
For convienience block_resource e.g. air_handler, 'air handler'
will be converted (ie. spaces will be converted to underscores
and the value will be converted to lower case and pluralized
if needed). block_ at the beginning may be ommited
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in convenience and omitted again and the :name vs :type
same docstring issues for get_block_resource, get_block_resources, and update_block_resource below

Update a building (using v1 api)
:param id: building id
:type id: int
:param name: name of building
Copy link
Contributor

Choose a reason for hiding this comment

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

no 'name' param in signature

@tallus
Copy link
Author

tallus commented May 11, 2017

Fixes in.

@tallus tallus merged commit b184e61 into master Jun 15, 2017
@fablet fablet deleted the api-client branch February 19, 2018 23:53
fablet pushed a commit that referenced this pull request Dec 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants