CSC/ECE 517 Spring 2020/P2000.Refactor pyrh oauth capabilities to a separate class

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

This project contributed to an open-source Python project called pyrh.

pyrh

pyrh is an unofficial python API for the Robinhood trading platform. It allows users to programmatically interact with their specific user accounts.

Specific Contributions

The goal of this project was to solve the authentication issues that users were encountering (the API not working after 1 day). An additional goal was to refactor the functionality that was all baked into a single class. Both were addressed in PR-215. [1] Additionally, extensive documentation was set up for the project for the first time. [2] And, CI testing was also set up and unit tests were written. [3] In essence the project was violating many DRY principles and the refactor helped reduce coupling and increase the separation of concerns.

Code Modifications

The core changes are seen across two files. [4] [5]

The before-after can be described as a change to abstract away login and session management to a separate class allowing the API class to (in the future) solely focus on parsing and managing the data received from the API.

Below is a list of code modifications:

  • Update pyproject.toml to add:
    • pytest
    • pytest-mock
    • requests-mock
    • coverage
    • pytest-cov
    • xdoctest
    • sphinx
      • some extension
      • flake8-docstrings
  • Update poetry.lock
  • Add cache.py for future cache files
  • Refactor endpoints.py
  • Refactor exceptions.py
  • Add sessionmanager.py
    • Add SessionManger class to handle auth
    • Implement auto-refresh (no more re-logging for each day)
  • Implement configs for coverage and pytest
  • Comment out all old tests
  • Add comprehensive testing for SessionManger
  • Add SSL verification (copied from pyarrow)
  • Create notebooks folder
  • Update ci pipeline name to build
  • Update gitignore to ignore mypy
  • Add autodoc and autosummary
  • Add API, developers, and changelog page to docs
  • Add mypy local run
  • Ignore type hints on trade_history_downloader (temporary)
  • Update example notebook.

Testing Plan

  • Test that the high-level login/logout functionality works
  • Test the low-level OAuth functionality
  • Test the get/post functionality with API
  • Test caching user credential abilities
  • Use mock data to set up tests (as live testing cannot be done with the API, test accounts are not provided)

Tests are seen in the unit testing file. [6]

These tests can be run by going through the documentation which is listed below.

Setting up the project to run the unit tests

The developer guidelines can be found at readthedocs. [7] Please specifically look for the section on how to run pytest. (unit testing)

Additionally, the automatic class reference documentation generated can be found in the documentation as well. [8] A guide on how to test the project can be found in the project Jupiter notebook [9]

Team Members

  • Adithya Balaji