Make Click context optional to be able to call functions from an external module
Problem
Since Click migration (v0.7.0), It is not possible to use a function which internally make a request. For external usage and tests without Click is not possible.
EndPoint class is coupled with Click context pass_context for custom endpoint or GTEST usage for BMA api string generation.
Would allow
- Write tests which requires requests is not possible (most of the tests)
- @tuxmain to use the transaction functions for ĞMixer and other projects to take advantages of Silkaj code.
Solution
In EndPoint class:
- Use
RuntimeErrorto detect that there is no Click context in case Click is installed and loaded - Use
ModuleNotFoundErrorin case Click is not installed - Previous point requires Python ≥ 3.6, and I didn’t found a way to import it with
__future__for Python 3.5 support. - To keep Python 3.5 support, I can just check for general exception for now. And, when Silkaj will drop Python 3.5, we could add back
ModuleNotFoundErrorexception.
Test
-
Test EndPoint().BMA_ENDPOINTwith click context -
Test EndPoint().BMA_ENDPOINTwithout click context -
Figure out how to test a singleton function -
Test with Python 3.5: Not found how to simulate missing module
After
-
Write test_tx_history_generate_table()test.
Edited by Moul