mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-08 07:48:26 -04:00
more
This commit is contained in:
@@ -6,7 +6,7 @@ import pytest
|
|||||||
import pytz
|
import pytz
|
||||||
import requests_mock
|
import requests_mock
|
||||||
from flask import current_app, url_for
|
from flask import current_app, url_for
|
||||||
from sqlalchemy import select
|
from sqlalchemy import delete, select
|
||||||
from sqlalchemy.orm.session import make_transient
|
from sqlalchemy.orm.session import make_transient
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
@@ -805,7 +805,7 @@ def mou_signed_templates(notify_service):
|
|||||||
def create_custom_template(
|
def create_custom_template(
|
||||||
service, user, template_config_name, template_type, content="", subject=None
|
service, user, template_config_name, template_type, content="", subject=None
|
||||||
):
|
):
|
||||||
template = Template.query.get(current_app.config[template_config_name])
|
template = db.session.get(Template, current_app.config[template_config_name])
|
||||||
if not template:
|
if not template:
|
||||||
data = {
|
data = {
|
||||||
"id": current_app.config[template_config_name],
|
"id": current_app.config[template_config_name],
|
||||||
@@ -826,7 +826,7 @@ def create_custom_template(
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def notify_service(notify_db_session, sample_user):
|
def notify_service(notify_db_session, sample_user):
|
||||||
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"])
|
service = db.session.get(Service, current_app.config["NOTIFY_SERVICE_ID"])
|
||||||
if not service:
|
if not service:
|
||||||
service = Service(
|
service = Service(
|
||||||
name="Notify Service",
|
name="Notify Service",
|
||||||
@@ -915,8 +915,12 @@ def restore_provider_details(notify_db_session):
|
|||||||
Note: This doesn't technically require notify_db_session (only notify_db), but kept as a requirement to encourage
|
Note: This doesn't technically require notify_db_session (only notify_db), but kept as a requirement to encourage
|
||||||
good usage - if you're modifying ProviderDetails' state then it's good to clear down the rest of the DB too
|
good usage - if you're modifying ProviderDetails' state then it's good to clear down the rest of the DB too
|
||||||
"""
|
"""
|
||||||
existing_provider_details = ProviderDetails.query.all()
|
existing_provider_details = (
|
||||||
existing_provider_details_history = ProviderDetailsHistory.query.all()
|
db.session.execute(select(ProviderDetails)).scalars().all()
|
||||||
|
)
|
||||||
|
existing_provider_details_history = (
|
||||||
|
db.session.execute(select(ProviderDetailsHistory)).scalars().all()
|
||||||
|
)
|
||||||
# make transient removes the objects from the session - since we'll want to delete them later
|
# make transient removes the objects from the session - since we'll want to delete them later
|
||||||
for epd in existing_provider_details:
|
for epd in existing_provider_details:
|
||||||
make_transient(epd)
|
make_transient(epd)
|
||||||
@@ -926,8 +930,9 @@ def restore_provider_details(notify_db_session):
|
|||||||
yield
|
yield
|
||||||
|
|
||||||
# also delete these as they depend on provider_details
|
# also delete these as they depend on provider_details
|
||||||
ProviderDetails.query.delete()
|
db.session.execute(delete(ProviderDetails))
|
||||||
ProviderDetailsHistory.query.delete()
|
db.session.execute(delete(ProviderDetailsHistory))
|
||||||
|
db.session.commit()
|
||||||
notify_db_session.commit()
|
notify_db_session.commit()
|
||||||
notify_db_session.add_all(existing_provider_details)
|
notify_db_session.add_all(existing_provider_details)
|
||||||
notify_db_session.add_all(existing_provider_details_history)
|
notify_db_session.add_all(existing_provider_details_history)
|
||||||
|
|||||||
@@ -38,7 +38,11 @@ def test_save_service_callback_api(sample_service):
|
|||||||
assert callback_api.updated_at is None
|
assert callback_api.updated_at is None
|
||||||
|
|
||||||
versioned = (
|
versioned = (
|
||||||
ServiceCallbackApi.get_history_model().query.filter_by(id=callback_api.id).one()
|
db.session.execute(
|
||||||
|
select(ServiceCallbackApi.get_history_model()).filter_by(id=callback_api.id)
|
||||||
|
)
|
||||||
|
.scalars()
|
||||||
|
.one()
|
||||||
)
|
)
|
||||||
assert versioned.id == callback_api.id
|
assert versioned.id == callback_api.id
|
||||||
assert versioned.service_id == sample_service.id
|
assert versioned.service_id == sample_service.id
|
||||||
@@ -98,7 +102,13 @@ def test_update_service_callback_can_add_two_api_of_different_types(sample_servi
|
|||||||
callback_type=CallbackType.COMPLAINT,
|
callback_type=CallbackType.COMPLAINT,
|
||||||
)
|
)
|
||||||
save_service_callback_api(complaint)
|
save_service_callback_api(complaint)
|
||||||
results = ServiceCallbackApi.query.order_by(ServiceCallbackApi.callback_type).all()
|
results = (
|
||||||
|
db.session.execute(
|
||||||
|
select(ServiceCallbackApi).order_by(ServiceCallbackApi.callback_type)
|
||||||
|
)
|
||||||
|
.scalars()
|
||||||
|
.all()
|
||||||
|
)
|
||||||
assert len(results) == 2
|
assert len(results) == 2
|
||||||
|
|
||||||
callbacks = [complaint.serialize(), delivery_status.serialize()]
|
callbacks = [complaint.serialize(), delivery_status.serialize()]
|
||||||
@@ -136,8 +146,12 @@ def test_update_service_callback_api(sample_service):
|
|||||||
assert updated.updated_at is not None
|
assert updated.updated_at is not None
|
||||||
|
|
||||||
versioned_results = (
|
versioned_results = (
|
||||||
ServiceCallbackApi.get_history_model()
|
db.session.execute(
|
||||||
.query.filter_by(id=saved_callback_api.id)
|
select(ServiceCallbackApi.get_history_model()).filter_by(
|
||||||
|
id=saved_callback_api.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.scalars()
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
assert len(versioned_results) == 2
|
assert len(versioned_results) == 2
|
||||||
|
|||||||
Reference in New Issue
Block a user