create TestHTTPClient that uses werkzueg test client, tests are passing
This commit is contained in:
@ -21,11 +21,9 @@ from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from capsulflask.shared import *
|
||||
from capsulflask import hub_model, spoke_model, cli
|
||||
from capsulflask.btcpay import client as btcpay
|
||||
from capsulflask.http_client import MyHTTPClient
|
||||
|
||||
|
||||
|
||||
def create_app():
|
||||
def create_app(http_client_factory):
|
||||
for var_name in [
|
||||
"SPOKE_HOST_TOKEN", "HUB_TOKEN", "STRIPE_SECRET_KEY",
|
||||
"BTCPAY_PRIVATE_KEY", "MAIL_PASSWORD"
|
||||
@ -133,7 +131,10 @@ def create_app():
|
||||
mylog_warning(app, "No MAIL_SERVER configured. capsul will simply print emails to stdout.")
|
||||
app.config['FLASK_MAIL_INSTANCE'] = StdoutMockFlaskMail()
|
||||
|
||||
app.config['HTTP_CLIENT'] = MyHTTPClient(timeout_seconds=int(app.config['INTERNAL_HTTP_TIMEOUT_SECONDS']))
|
||||
# allow a mock http client to be injected by the test code.
|
||||
app.config['HTTP_CLIENT'] = http_client_factory(int(app.config['INTERNAL_HTTP_TIMEOUT_SECONDS']))
|
||||
|
||||
|
||||
|
||||
app.config['BTCPAY_ENABLED'] = False
|
||||
if app.config['BTCPAY_URL'] != "":
|
||||
@ -160,7 +161,7 @@ def create_app():
|
||||
|
||||
# debug mode (flask reloader) runs two copies of the app. When running in debug mode,
|
||||
# we only want to start the scheduler one time.
|
||||
if is_running_server and (not app.debug or config.get('WERKZEUG_RUN_MAIN') == 'true'):
|
||||
if is_running_server and not app.config['TESTING'] and (not app.debug or config.get('WERKZEUG_RUN_MAIN') == 'true'):
|
||||
scheduler = BackgroundScheduler()
|
||||
heartbeat_task_url = f"{app.config['HUB_URL']}/hub/heartbeat-task"
|
||||
heartbeat_task_headers = {'Authorization': f"Bearer {app.config['HUB_TOKEN']}"}
|
||||
|
||||
Reference in New Issue
Block a user