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

Code review #14

Closed
kracekumar opened this issue Oct 30, 2018 · 4 comments
Closed

Code review #14

kracekumar opened this issue Oct 30, 2018 · 4 comments

Comments

@kracekumar
Copy link

@jbedorf and @MrFlynn. The overall code looks good. There are few minor suggested changes by me. @jvanheugten please add your reviews too. Please feel to modify or ignore. Though, I haven't tested the workflow by setting up the repo.

Typing

Requests

   if res.status_code == 401:
      # Handle unauthenticated requests.
      raise ZoomAPIException(401, 'Unauthorized', res.request, 'Not authenticated.')
    elif res.status_code == 409:
      # Handle error where content may have been removed already.
      raise ZoomAPIException(409, 'Resource Conflict', res.request, 'File deleted already.')

the above code can be written as

status_code = res.status_code 
if 400 <= status_code <= 499:
   message = {401: 'Not authenticated.', 409: 'File deleted already.')
   raise ZoomAPIException(status_code, res.reason, res.request, message.get(status_code, '')

Response API: http://docs.python-requests.org/en/master/api/#requests.Response

if 200 <= status_code <= 299:
# All well
elif 300 <= status_code <= 399:
# Server is redirecting, we can't do much
elif 400 <= status_code <= 499:
# Something we did wrong,
elif 500 <= status_code <= 599:
# Zoom Server Error
else:
# Never seen this but possible

General

def download_recording(self, url: str) -> str:
    """Downloads video file from Zoom to local folder.
    Args:
      url: Download URL for meeting recording.

    Returns: Path to the recording
    """

this repo follows

def download_recording(self, url: str) -> str:
    """Downloads video file from Zoom to local folder.
    :param url: Download URL for meeting recording.
    :return: Path to the recording
    """
  • The URLS for various services are declared at multiple places. It can be put under one file with multiple classes like
class ZoomURLS(Enum):
   recordings: 'https://api.zoom.us/v2/meetings/{id}/recordings'
   delete_recordings: 'https://api.zoom.us/v2/meetings/{id}/recordings/{rid}'
   ...

The advantage of the method is, when zoom changes it's API, we can find all the URLS in one place and modify.

Typos

  • entries is misspelled as entrees in README.

Testing

We can write unit tests for the code, we have written like ConfigParsers and other services specific code. One can mock the request, and response using Python Mock library, Responses. Once you have a list of scenarios like Zoom recording file is missing, record files are available then write tests for specific code parts.

@jvanheugten
Copy link

Not much to add myself.
I agree with Krace that moving URLs to single location is useful, see also:

self._scopes = ['https://www.googleapis.com/auth/drive.file']
.
We might want to use the same bin/git and style_check.sh/.pylintrc/.pycodestyle as in the other repositories.
Lots of typing with list, dict, etc., but normally you would use typing's List and Dict etc.

Maybe run:

pip install pipreqs pip-tools
pipreqs --force ./; mv requirements.txt requirements.in; pip-compile

to get a more reproducible set of dependencies (with versions).

From a security perspective, I don't know if it is great to have a plain readable config.yaml that gives access to drive, zoom, and slack.

@MrFlynn
Copy link
Contributor

MrFlynn commented Oct 30, 2018

Thanks for the comments, everyone. Most of this stuff should be fairly easy to fix, though I have a couple of comments.

https://github.com/minds-ai/zoom-drive-connector/blob/master/main.py#L32. The function returns a list, should be annotated as List[Dict[str, str]]. If you find difficult to annotate a dict, consider using namedtuple.

@kracekumar I generally like to avoid namedtuples due to performance considerations (slow startup times). This is a fairly small application so it wouldn't matter here, but it's a practice I like to follow.

In terms of docstrings, I've been writing them in reStructured Text format (as recommended by PEP 287). The reason for this is that this repository was started before we had a stated company-wide docstring format. As a consequence, most of the Python code written by IT uses this format now. I think this is part of a bigger discussion on whether to migrate IT's docstring formatting to something else.

@jvanheugten In terms of having access keys and credentials in a file, there's a tradeoff to be made here: either keeping everything on disk or using environment variables (which get logged in your shell history anyway). The configuration file will likely be in someone's home folder which should only be accessible by one person.

@MrFlynn
Copy link
Contributor

MrFlynn commented Oct 30, 2018

So here's a preliminary todo list. Feel free to comment on this so I can add stuff.

  • Update type annotations to use proper/more explicit format.
  • Update requests error handling code blocks (w.r.t. what Krace wrote in the original comment in this issue).
  • Move API URLs to enums to reduce duplicate strings in code.
  • Fix typo in README.
  • Implement testing using mock unittests or responses library (personally I prefer the former because it's built-in but I'm open to recommendations).

@MrFlynn MrFlynn mentioned this issue Nov 2, 2018
@MrFlynn
Copy link
Contributor

MrFlynn commented Nov 12, 2018

All changes applied in #16 and #17.

@MrFlynn MrFlynn closed this as completed Nov 12, 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

No branches or pull requests

3 participants