Skip to content

Commit

Permalink
Rename /template/category to /template-category
Browse files Browse the repository at this point in the history
- Adjust tests
- formatting
  • Loading branch information
whabanks committed Jun 25, 2024
1 parent 041a647 commit 0be6d19
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
3 changes: 2 additions & 1 deletion app/dao/template_categories_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def dao_delete_template_category_by_id(template_category_id, cascade=False):
for template in templates:
# Get the a default category that matches the previous priority of the template, based on template type
default_category_id = _get_default_category_id(
template_category.sms_process_type if template.template_type == "sms"
template_category.sms_process_type
if template.template_type == "sms"
else template_category.email_process_type
)
template.category = dao_get_template_category_by_id(default_category_id)
Expand Down
2 changes: 1 addition & 1 deletion app/template/template_category_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
template_category_blueprint = Blueprint(
"template_category",
__name__,
url_prefix="/template/category",
url_prefix="/template-category",
)

register_errors(template_category_blueprint)
Expand Down
2 changes: 1 addition & 1 deletion tests/app/dao/test_templates_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,4 @@ def test_dao_update_template_category(sample_template, sample_template_category)

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
assert history.updated_at == updated_template.updated_at
3 changes: 1 addition & 2 deletions tests/app/template/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,6 @@ def test_should_template_be_redacted():


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.
Expand All @@ -1574,4 +1573,4 @@ def test_update_templates_category(sample_template, sample_template_category, ad

template = dao_get_template_by_id(sample_template.id)

assert template.category.id == sample_template_category.id
assert template.category.id == sample_template_category.id
17 changes: 5 additions & 12 deletions tests/app/template/test_template_category_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ def test_should_create_new_template_category(client, notify_db, notify_db_sessio
"email_process_type": "bulk",
"hidden": True,
}

auth_header = create_authorization_header()

response = client.post(
"/template/category",
url_for("template_category.create_template_category"),
headers=[("Content-Type", "application/json"), auth_header],
json=data,
)
Expand All @@ -39,7 +38,7 @@ def test_should_create_new_template_category(client, notify_db, notify_db_sessio
def test_get_template_category_by_id(client, sample_template_category):
auth_header = create_authorization_header()
response = client.get(
f"/template/category/{sample_template_category.id}",
url_for("template_category.get_template_category", template_category_id=sample_template_category.id),
headers=[("Content-Type", "application/json"), auth_header],
)

Expand All @@ -55,7 +54,7 @@ def test_get_template_category_by_id(client, sample_template_category):

def test_get_template_category_by_template_id(client, notify_db, notify_db_session, sample_template_category):
category = sample_template_category
template = create_sample_template(notify_db, notify_db_session, template_category=category)
template = create_sample_template(notify_db, notify_db_session, category=category)

auth_header = create_authorization_header()
endpoint = url_for("template_category.get_template_category_by_template_id", template_id=template.id)
Expand Down Expand Up @@ -104,18 +103,12 @@ def test_get_template_categories(
):
auth_header = create_authorization_header()

query_params = {}
if template_type:
query_params["template_type"] = template_type
if hidden:
query_params["hidden"] = hidden

query_string = f"?{urlencode(query_params)}" if len(query_params) > 0 else ""
endpoint = url_for("template_category.get_template_categories", template_type=template_type, hidden=hidden)

mocker.patch("app.dao.template_categories_dao.dao_get_all_template_categories", return_value=[sample_template_category])

response = client.get(
f"/template/category{query_string}",
endpoint,
headers=[("Content-Type", "application/json"), auth_header],
)

Expand Down
27 changes: 13 additions & 14 deletions tests/app/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Notification,
ServiceSafelist,
)
from tests.app.conftest import create_template_category
from tests.app.db import (
create_inbound_number,
create_letter_contact,
Expand All @@ -34,10 +35,6 @@
save_notification,
)

from tests.app.conftest import (
create_template_category,
)


@pytest.mark.parametrize("mobile_number", ["650 253 2222", "+1 650 253 2222"])
def test_should_build_service_safelist_from_mobile_number(mobile_number):
Expand Down Expand Up @@ -370,18 +367,20 @@ def test_template_folder_is_parent(sample_service):
(EMAIL_TYPE, BULK, PRIORITY, PRIORITY, BULK),
],
)
def test_template_process_type(notify_db, notify_db_session, template_type, process_type, sms_process_type, email_process_type, expected_template_process_type):
def test_template_process_type(
notify_db,
notify_db_session,
template_type,
process_type,
sms_process_type,
email_process_type,
expected_template_process_type,
):
category = create_template_category(
notify_db,
notify_db_session,
sms_process_type = sms_process_type,
email_process_type = email_process_type
notify_db, notify_db_session, sms_process_type=sms_process_type, email_process_type=email_process_type
)
template = create_template(
service=create_service(),
template_type=template_type,
process_type=process_type,
category=category
service=create_service(), template_type=template_type, process_type=process_type, category=category
)

assert template.template_process_type == expected_template_process_type
Expand All @@ -403,4 +402,4 @@ class TestNotificationModel:
def test_queue_name_in_notifications(self, sample_service):
template = create_template(sample_service, template_type="email")
notification = save_notification(create_notification(template, to_field="[email protected]", queue_name="tester"))
assert notification.queue_name == "tester"
assert notification.queue_name == "tester"

0 comments on commit 0be6d19

Please sign in to comment.