CSC/ECE 517 Spring 2020/P2000.Refactor pyrh oauth capabilities to use marshmallow
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.
Project Purpose
The goal of this project is to refactor the initial OAuth class that was created to leverage API best practices handling serialization/deserialization. An existing project called marshmallow handles the use case of the custom code that was initially written to manage serialization and deserialization. It would be prudent to adopt that package. Additionally, the internal code that passed around JSON dictionaries likely should use python object models which can more easily be manipulated allowing the business logic to be moved to the models. Additionally, this data model-based framework will make it easy to implement further refactors as more data models are introduced for other parts of the API besides auth.
Project Design
New classes:
- BaseModel: a model that any new model will inherit from, provides default data representation functionality and inherit from Python's SimpleNamespace
- BaseSchema: a Schema class that provides default functionality for serializing the object attributes that matter for a particular object
- Challenge: A model that represents the data returned by an OAuth Challenge from that designated endpoint
- ChallengeSchema: the schema and validations associated with the Challenge model
- OAuth: A model that represents the data returned by the OAuth token generation endpoint
- OAuthSchema: the schema and validations associated with the OAuth model
- SessionManager (existing): a class that implements functionality to interact with the Robinhood authorization endpoint API
- SessionManagerSchema: the schema associated with the SessionManager model
The inheritance diagrams are listed below:
File:SessionManager.png SessionManager inheritance diagram
Code Modifications
TBD
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. [1]
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. [2] 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. [3] A guide on how to test the project can be found in the project Jupiter notebook [4]
Team Members
- Adithya Balaji