Skip to content

Commit

Permalink
Merge branch 'main' into repo-sync/site-reliability-engineering/default
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai authored Jul 9, 2024
2 parents f5dc6f0 + 2e04667 commit 31c5815
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 14 deletions.
7 changes: 7 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
COMPLAINT_CALLBACK_TYPE = "complaint"
SERVICE_CALLBACK_TYPES = [DELIVERY_STATUS_CALLBACK_TYPE, COMPLAINT_CALLBACK_TYPE]

SHORT_CODE = "short_code"
LONG_CODE = "long_code"

sms_sending_vehicles = db.Enum(*[SHORT_CODE, LONG_CODE], name="sms_sending_vehicles")


def filter_null_value_fields(obj):
return dict(filter(lambda x: x[1] is not None, obj.items()))
Expand Down Expand Up @@ -1046,6 +1051,7 @@ class TemplateCategory(BaseModel):
hidden = db.Column(db.Boolean, nullable=False, default=False)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
updated_at = db.Column(db.DateTime, onupdate=datetime.datetime.utcnow)
sms_sending_vehicle = db.Column(sms_sending_vehicles, nullable=False, default="long_code")

def serialize(self):
return {
Expand All @@ -1059,6 +1065,7 @@ def serialize(self):
"hidden": self.hidden,
"created_at": self.created_at,
"updated_at": self.updated_at,
"sms_sending_vehicle": self.sms_sending_vehicle,
}

@classmethod
Expand Down
73 changes: 73 additions & 0 deletions migrations/versions/0456_update_template_categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Revision ID: 0456_update_template_categories
Revises: 0455_add_starter_category
Create Date: 2024-06-11 13:32:00
"""
import sqlalchemy as sa
from alembic import op

revision = "0456_update_template_categories"
down_revision = "0455_add_starter_category"

LOW_CATEGORY_ID = "0dda24c2-982a-4f44-9749-0e38b2607e89"
MEDIUM_CATEGORY_ID = "f75d6706-21b7-437e-b93a-2c0ab771e28e"
HIGH_CATEGORY_ID = "c4f87d7c-a55b-4c0f-91fe-e56c65bb1871"
CAT_ALERT_ID = "1d8ce435-a7e5-431b-aaa2-a418bc4d14f9"
CAT_AUTH_ID = "b6c42a7e-2a26-4a07-802b-123a5c3198a9"
CAT_AUTO_ID = "977e2a00-f957-4ff0-92f2-ca3286b24786"
CAT_DECISION_ID = "e81678c0-4897-4111-b9d0-172f6b595f89"
CAT_INFO_ID = "207b293c-2ae5-48e8-836d-fcabd60b2153"
CAT_REMINDER_ID = "edb966f3-4a4c-47a4-96ab-05ff259b919c"
CAT_REQUEST_ID = "e0b8fbe5-f435-4977-8fc8-03f13d9296a5"
CAT_STATUS_ID = "55eb1137-6dc6-4094-9031-f61124a279dc"
CAT_TEST_ID = "7c16aa95-e2e1-4497-81d6-04c656520fe4"

SHORT_CODE_CATS = (HIGH_CATEGORY_ID, CAT_AUTH_ID, CAT_AUTO_ID, CAT_DECISION_ID, CAT_REMINDER_ID, CAT_REQUEST_ID, CAT_STATUS_ID)
LONG_CODE_CATS = (LOW_CATEGORY_ID, MEDIUM_CATEGORY_ID, CAT_ALERT_ID, CAT_INFO_ID, CAT_TEST_ID)

sms_options = ("short_code", "long_code")
sms_sending_vehicle = sa.Enum(*sms_options, name="sms_sending_vehicle")


def upgrade():
sms_sending_vehicle.create(op.get_bind(), checkfirst=True)

op.add_column(
"template_categories", sa.Column("sms_sending_vehicle", sms_sending_vehicle, server_default="long_code", nullable=False)
)

# Update the generic categories
op.execute(
"UPDATE template_categories SET sms_process_type = 'bulk', email_process_type = 'bulk' WHERE id = '{}'".format(
LOW_CATEGORY_ID,
)
)
op.execute(
"UPDATE template_categories SET sms_process_type = 'normal', email_process_type = 'normal' WHERE id = '{}'".format(
MEDIUM_CATEGORY_ID,
)
)
op.execute(
"UPDATE template_categories SET sms_process_type = 'priority', email_process_type = 'priority' WHERE id = '{}'".format(
HIGH_CATEGORY_ID,
)
)

# Update the sms_sending_vehicle for the starter categories

op.execute(
"UPDATE template_categories SET sms_sending_vehicle = 'short_code' WHERE id in {}".format(
SHORT_CODE_CATS,
)
)

op.execute(
"UPDATE template_categories SET sms_sending_vehicle = 'long_code' WHERE id in {}".format(
LONG_CODE_CATS,
)
)


def downgrade():
op.drop_column("template_categories", "sms_sending_vehicle")
sms_sending_vehicle.drop(op.get_bind(), checkfirst=True)
51 changes: 37 additions & 14 deletions tests/app/dao/test_template_categories_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,45 @@
from tests.app.conftest import create_sample_template


def test_create_template_category(notify_db_session):
data = {
"name_en": "english",
"name_fr": "french",
"description_en": "english description",
"description_fr": "french description",
"sms_process_type": NORMAL,
"email_process_type": NORMAL,
"hidden": False,
}
class TestCreateTemplateCategory:
def test_create_template_category(self, notify_db_session):
data = {
"name_en": "english",
"name_fr": "french",
"description_en": "english description",
"description_fr": "french description",
"sms_process_type": NORMAL,
"email_process_type": NORMAL,
"hidden": False,
"sms_sending_vehicle": "short_code",
}

template_category = TemplateCategory(**data)
dao_create_template_category(template_category)

template_category = TemplateCategory(**data)
dao_create_template_category(template_category)
temp_cat = dao_get_all_template_categories()
assert TemplateCategory.query.count() == 1
assert len(temp_cat) == 1
assert temp_cat[0].sms_sending_vehicle == "short_code"

def test_create_template_category_with_no_sms_sending_vehicle(self, notify_db_session):
data = {
"name_en": "english",
"name_fr": "french",
"description_en": "english description",
"description_fr": "french description",
"sms_process_type": NORMAL,
"email_process_type": NORMAL,
"hidden": False,
}

template_category = TemplateCategory(**data)
dao_create_template_category(template_category)

assert TemplateCategory.query.count() == 1
assert len(dao_get_all_template_categories()) == 1
temp_cat = dao_get_all_template_categories()
assert TemplateCategory.query.count() == 1
assert len(temp_cat) == 1
assert temp_cat[0].sms_sending_vehicle == "long_code" # default value


@pytest.mark.parametrize(
Expand Down

0 comments on commit 31c5815

Please sign in to comment.