mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-10 23:32:27 -05:00
try to lazy init db another way
This commit is contained in:
@@ -88,9 +88,10 @@ encryption = None
|
||||
zendesk_client = None
|
||||
redis_store = RedisClient()
|
||||
document_download_client = None
|
||||
notification_provider_clients = None
|
||||
|
||||
notification_provider_clients = NotificationProviderClients()
|
||||
|
||||
# LocalProxy doesn't evaluate the target immediately, but defers
|
||||
# resolution to runtime. So there is no monkeypatching concern.
|
||||
api_user = LocalProxy(lambda: g.api_user)
|
||||
authenticated_service = LocalProxy(lambda: g.authenticated_service)
|
||||
|
||||
@@ -181,10 +182,12 @@ def create_app(application):
|
||||
logging.init_app(application)
|
||||
|
||||
# start lazy initialization for gevent
|
||||
# NOTE: notify_celery and redis_store are safe to construct here
|
||||
# because all entry points (gunicorn_entry.py, run_celery.py) apply
|
||||
# monkey.patch_all() first.
|
||||
# Do NOT access or use them before create_app() is called and don't
|
||||
# call create_app() in multiple places.
|
||||
|
||||
# Set db engine settings here for now.
|
||||
# They were not being set previous (despite environmental variables with appropriate
|
||||
# sounding names) and were defaulting to low values
|
||||
db = SQLAlchemy(
|
||||
engine_options={
|
||||
"pool_size": config.Config.SQLALCHEMY_POOL_SIZE,
|
||||
@@ -213,9 +216,7 @@ def create_app(application):
|
||||
aws_sns_client.init_app(application)
|
||||
encryption = Encryption()
|
||||
encryption.init_app(application)
|
||||
|
||||
# end lazy initialization
|
||||
|
||||
notification_provider_clients = NotificationProviderClients()
|
||||
# If a stub url is provided for SES, then use the stub client rather than the real SES boto client
|
||||
email_clients = (
|
||||
[aws_ses_stub_client]
|
||||
@@ -225,6 +226,7 @@ def create_app(application):
|
||||
notification_provider_clients.init_app(
|
||||
sms_clients=[aws_sns_client], email_clients=email_clients
|
||||
)
|
||||
# end lazy initialization
|
||||
|
||||
notify_celery.init_app(application)
|
||||
redis_store.init_app(application)
|
||||
|
||||
@@ -2,8 +2,7 @@ import pytest
|
||||
from freezegun import freeze_time
|
||||
from sqlalchemy import select
|
||||
|
||||
import application
|
||||
from app import create_app, db
|
||||
from app import db
|
||||
from app.dao.annual_billing_dao import (
|
||||
dao_create_or_update_annual_billing_for_year,
|
||||
dao_get_all_free_sms_fragment_limit,
|
||||
@@ -19,7 +18,6 @@ from tests.app.db import create_annual_billing, create_service
|
||||
|
||||
|
||||
def test_dao_update_free_sms_fragment_limit(notify_db_session, sample_service):
|
||||
create_app(application)
|
||||
new_limit = 9999
|
||||
year = get_current_calendar_year_start_year()
|
||||
dao_create_or_update_annual_billing_for_year(sample_service.id, new_limit, year)
|
||||
|
||||
Reference in New Issue
Block a user