Skip to content

Commit

Permalink
updated the template category model (#2211)
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai authored Jul 9, 2024
1 parent 9db1465 commit 2e04667
Show file tree
Hide file tree
Showing 2 changed files with 44 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
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 2e04667

Please sign in to comment.