fix for failing tests

This commit is contained in:
Aditi Anand
2024-03-20 10:57:04 -04:00
parent 5d15560538
commit 8bc1091f73
6 changed files with 19 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ from flask import current_app, json
from notifications_python_client.authentication import create_jwt_token from notifications_python_client.authentication import create_jwt_token
from notifications_utils.recipients import RecipientCSV from notifications_utils.recipients import RecipientCSV
from notifications_utils.template import SMSMessageTemplate from notifications_utils.template import SMSMessageTemplate
from sqlalchemy import and_ from sqlalchemy import and_, text
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
@@ -173,13 +173,15 @@ def insert_inbound_numbers_from_file(file_name):
print(f"Inserting inbound numbers from {file_name}") print(f"Inserting inbound numbers from {file_name}")
with open(file_name) as file: with open(file_name) as file:
sql = "insert into inbound_numbers values('{}', '{}', 'sns', null, True, now(), null);" sql = text(
"insert into inbound_numbers values(:uuid, :line, 'sns', null, True, now(), null);"
)
for line in file: for line in file:
line = line.strip() line = line.strip()
if line: if line:
print(line) print(line)
db.session.execute(sql.format(uuid.uuid4(), line)) db.session.execute(sql, {"uuid": str(uuid.uuid4()), "line": line})
db.session.commit() db.session.commit()
@@ -333,7 +335,7 @@ def update_jobs_archived_flag(start_date, end_date):
and created_at < (date :end + time '00:00:00') and created_at < (date :end + time '00:00:00')
""" """
result = db.session.execute( result = db.session.execute(
sql, {"start": process_date, "end": process_date + timedelta(days=1)} text(sql), {"start": process_date, "end": process_date + timedelta(days=1)}
) )
db.session.commit() db.session.commit()
current_app.logger.info( current_app.logger.info(

View File

@@ -206,7 +206,7 @@ def dao_fetch_all_services_by_user(user_id, only_active=False):
query = ( query = (
Service.query.filter(Service.users.any(id=user_id)) Service.query.filter(Service.users.any(id=user_id))
.order_by(asc(Service.created_at)) .order_by(asc(Service.created_at))
.options(joinedload("users")) .options(joinedload(Service.users))
) )
if only_active: if only_active:

View File

@@ -17,7 +17,7 @@ session events.
import datetime import datetime
from sqlalchemy import Column, ForeignKeyConstraint, Integer, Table, util from sqlalchemy import Column, ForeignKeyConstraint, Integer, Table, util
from sqlalchemy.orm import attributes, class_mapper, object_mapper, registry from sqlalchemy.orm import attributes, object_mapper, registry
from sqlalchemy.orm.properties import ColumnProperty, RelationshipProperty from sqlalchemy.orm.properties import ColumnProperty, RelationshipProperty
@@ -169,7 +169,9 @@ def _add_version_for_non_super_history_mapper(super_history_mapper, local_mapper
def _col_copy(col): def _col_copy(col):
orig = col orig = col
col = Column(col.name, col.type, nullable=col.nullable, unique=False) col = Column(
col.name, col.type, nullable=col.nullable, unique=False, default=col.default
)
orig.info["history_copy"] = col orig.info["history_copy"] = col
# if the column is nullable, we could end up overwriting an on-purpose null value with a default. # if the column is nullable, we could end up overwriting an on-purpose null value with a default.
@@ -189,7 +191,8 @@ class Versioned(object):
@classmethod @classmethod
def __declare_last__(cls): def __declare_last__(cls):
_history_mapper(class_mapper(cls)) if not hasattr(cls, "__history_mapper__"):
_history_mapper(cls.__mapper__)
@classmethod @classmethod
def get_history_model(cls): def get_history_model(cls):

View File

@@ -7,8 +7,8 @@ Create Date: 2023-05-23 10:03:10.485368
""" """
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy import text from sqlalchemy import text
from sqlalchemy.dialects import postgresql
revision = "0395_remove_intl_letters_perm" revision = "0395_remove_intl_letters_perm"
down_revision = "0394_remove_contact_list" down_revision = "0394_remove_contact_list"

View File

@@ -469,7 +469,8 @@ def upgrade():
postgresql_using=enum_using("notification_type", NotificationType), postgresql_using=enum_using("notification_type", NotificationType),
) )
# Clobbering bad data here. These are values we don't use any more, and anything with them is unnecessary. # Clobbering bad data here. These are values we don't use any more, and anything with them is unnecessary.
op.execute(""" op.execute(
"""
delete from delete from
service_permissions service_permissions
where where
@@ -480,7 +481,8 @@ def upgrade():
'international_letters', 'international_letters',
'broadcast' 'broadcast'
); );
""") """
)
op.alter_column( op.alter_column(
"service_permissions", "service_permissions",
"permission", "permission",

View File

@@ -69,7 +69,7 @@ def _notify_db(notify_api):
yield db yield db
db.session.remove() db.session.close_all()
db.engine.dispose() db.engine.dispose()