# Purpose Let's find a place to docoment non straightforward design decisions. ## 02nd Oct 2020 - Kim It's already mentioned in Development.md. I spend far too much time figuring out that we have created a nasty workaround in server.py. So the problem looks like this: The fixtures are creating the app anew for each test in test_controller. For some reason hwi-view-endpoints are somehow treated differently then the normal endpoints. As a result, the second test gets a app-object which, for some reason doesn't have the normal endpoints, but just the hwi-endpoint. A healthy app.view_functions looks like this: ``` {'static': >, 'hwi_server.index': , 'hwi_server.api': , 'hwi_server.hwi_bridge_settings': , 'combine': , 'broadcast': , 'index': , 'about': , 'login': , 'register': , 'logout': , 'settings': , 'hwi_settings': , 'general_settings': , 'bitcoin_core_settings': , 'auth_settings': , 'new_wallet_type': , 'new_wallet': , 'wallet': , 'wallets_overview': , 'singlesig_setup_wizard': , 'wallet_tx': , 'wallet_tx_history': , 'wallet_tx_utxo': , 'wallet_receive': , 'fees': , 'txout_set_info': , 'get_scantxoutset_status': , 'get_wallet_rescan_progress': , 'wallet_send': , 'wallet_sendnew': , 'wallet_importpsbt': , 'wallet_sendpending': , 'wallet_settings': , 'new_device': , 'device': } ``` An unhelathy like this: ``` {'static': >, 'hwi_server.index': , 'hwi_server.api': , 'hwi_server.hwi_bridge_settings': } ``` Feel free to beat me for the brittle if-clause in server.py but please solve the issue in the first place for this as well :-). ## 19nd Feb 2020 - k9ert The ApplicationFactory-pattern is not that straightforward. There are loads of pifalls and different ways to go. While finding a proper way to do it, one thing became clear: You need to separate the instantiation and the initialisation of the Application. (from singleton.py) ```python __main__.py app = logic.create_app() app.app_context().push() # (...) logic.init_app(app) ``` If you would put everything in the create-call, you can't import code which is dependent on an initialized ApplicationContext, you can't do "from flask import current_app". So you have to push the app_context but on the other side, you don't want to do that from within the create_app-function because this would be a quite shitty side-effect which srews up your whole dependency injection.