Skip to content

Commit

Permalink
Add tests that were missed for template rest and dao
Browse files Browse the repository at this point in the history
  • Loading branch information
whabanks committed Jun 25, 2024
1 parent f927c99 commit 041a647
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tests/app/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def create_sample_template(
subject_line="Subject",
user=None,
service=None,
template_category=None,
category=None,
created_by=None,
process_type="normal",
permissions=[EMAIL_TYPE, SMS_TYPE],
Expand Down Expand Up @@ -363,8 +363,8 @@ def create_sample_template(
data.update({"subject": subject_line})
if template_type == "letter":
data["postage"] = "second"
if template_category:
data["category"] = template_category
if category:
data["category"] = category
template = Template(**data)
dao_create_template(template)

Expand Down Expand Up @@ -400,6 +400,7 @@ def sample_template(
service=None,
created_by=None,
process_type="normal",
category=None,
permissions=[EMAIL_TYPE, SMS_TYPE],
)

Expand Down
14 changes: 14 additions & 0 deletions tests/app/dao/test_templates_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
dao_get_template_versions,
dao_redact_template,
dao_update_template,
dao_update_template_category,
dao_update_template_reply_to,
)
from app.models import Template, TemplateHistory, TemplateRedacted
Expand Down Expand Up @@ -490,3 +491,16 @@ def test_template_postage_constraint_on_update(sample_service, sample_user):
created.postage = "third"
with pytest.raises(expected_exception=SQLAlchemyError):
dao_update_template(created)


def test_dao_update_template_category(sample_template, sample_template_category):
dao_update_template_category(sample_template.id, sample_template_category.id)

updated_template = Template.query.get(sample_template.id)
assert updated_template.template_category_id == sample_template_category.id
assert updated_template.updated_at is not None
assert updated_template.version == 2

history = TemplateHistory.query.filter_by(id=sample_template.id, version=updated_template.version).one()
assert history.template_category_id == None

Check notice

Code scanning / CodeQL

Testing equality to None Note

Testing for None should use the 'is' operator.
assert history.updated_at == updated_template.updated_at
17 changes: 17 additions & 0 deletions tests/app/template/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,3 +1558,20 @@ def test_should_template_be_redacted():

dao_update_organisation(some_org.id, organisation_type="province_or_territory")
assert should_template_be_redacted(some_org)


def test_update_templates_category(sample_template, sample_template_category, admin_request):

assert sample_template.category == None

Check notice

Code scanning / CodeQL

Testing equality to None Note

Testing for None should use the 'is' operator.

response = admin_request.post(

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable response is not used.
"template.update_templates_category",
service_id=sample_template.service_id,
template_id=sample_template.id,
template_category_id=sample_template_category.id,
_expected_status=200,
)

template = dao_get_template_by_id(sample_template.id)

assert template.category.id == sample_template_category.id

0 comments on commit 041a647

Please sign in to comment.