1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2024-12-26 14:34:31 +01:00
dspace-statistics-api/dspace_statistics_api
Alan Orth d4518d62ad
dspace_statistics_api/app.py: Refactor for testability
I thought it was clever to only import these in the on_post handler
because they aren't needed elsewhere, but it turns out that this is
not a common pattern and even causes problems with testability.

First, if the imports are at the top of the file as PEP8 recommends,
then the WSGI server will import them once when it loads the app and
they remain in memory for the lifecycle of the app. If the imports
are in the on_post handler they would be re-imported on every request!

Second, this pattern of importing in a method makes it tricky to use
object patching in mocks.

See: https://www.python.org/dev/peps/pep-0008/#imports
2020-10-05 20:43:50 +03:00
..
docs dspace_statistics_api/docs/index.html: Fix whitespace 2020-09-25 13:33:45 +03:00
__init__.py Refactor project structure 2018-10-28 11:14:21 +02:00
app.py dspace_statistics_api/app.py: Refactor for testability 2020-10-05 20:43:50 +03:00
config.py Format code with black 2019-11-27 12:30:06 +02:00
database.py dspace_statistics_api: Use f-strings instead of format() 2020-03-02 11:24:29 +02:00
indexer.py dspace_statistics_api/indexer.py: Fix Python comment 2020-09-25 13:35:05 +03:00
items.py dspace_statistics_api/items.py: Remove executable bit 2020-10-05 14:33:36 +03:00
util.py Refactor /items POST handler to use a before hook 2020-09-26 18:40:52 +03:00