Police-Data-Accessibility-Project / data-sources-app

An API and UI for using and maintaining the Data Sources database
MIT License
4 stars 5 forks source link

Refactor: Simplify DynamicMagicMock Class #404

Closed maxachis closed 3 months ago

maxachis commented 3 months ago

Context

I have a class called DynamicMagicMock, which aims to group together related mocks and patch them all at once and provide return values as needed. It helps to consolidate and simplify what would otherwise be a more tedious process of passing a large number of functions.

However, it does a few things it doesn't need to do:

  1. Many variants of it declare mocks that don't need to be declared -- they will be automatically generated when called.
  2. If we eliminate those, all that remains are mocks which need to be patched -- in which case, we can simplify the logic so that we don't need to declare each one of those to be patched -- we can simply provide the patch root and that's it.

In addition, some usages of the Dynamic Magic Mock are unnecessary, and can be replaced with a simple MagicMock.

Requirements

Tests

Docs

Open questions