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. This is an unofficial python API for the Robinhood trading platform. It allows users to programmatically interact with their specific user accounts.
Pre-Development Documentation
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
(Please note that this is a custom project and does not have an Expertiza project requirements)
In order to more properly follow object-oriented design practices, the large SessionManager class will be aided by data manager classes that encapsulate both the data and business logic associated with that data to cut on bloat. The *Schema classes will aid in the serialization/deserialization of those data model classes. The use of the existing python package "Marshmallow" will aid in that data serialization/validation process.
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:
OAuth inheritance diagram
SessionManager inheritance diagram
Testing Plan
The testing plan is quite simple in this case and revolves around these key ideas:
- Test that none of the existing authentication functionality is broken
- Test that the new data models can be serialized/deserialized
- Test that the SessionManager class can be serialized to the custom data cache location
- Update tests to use FreezeGun where DateTime is required
Post-Development Documentation
Code Modifications
TODO
Setting up the project to run the unit tests
TODO
Team Members
- Adithya Balaji