mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 05:59:44 -04:00
Add Service.get_templates method with filters by type and folder
With the addition of template folders we need to filter templates based on a combination of type and parent folder ID. This replaces the existing `templates_by_type` method with `get_templates`, which supports both type and parent folder filters, avoiding a need to create specific methods for each use case. We still need the templates property to exist in some way in order to cache it, but it needs to be clear that it's different from `.get_templates`. One option was to make it "private" (i.e. `_templates`), and always use `.get_templates` in the rest of the code, but this requires adding "include all folders" to `.get_templates`, which doesn't have an obvious interface since `parent_folder_id=None` already means "top-level only". This will probably come up again when we need to look into adding templates from nested folders into the page for live search, but for now renaming `Service.templates` to `.all_templates` makes it clear what the property contains.
This commit is contained in:
@@ -563,13 +563,13 @@ def test_should_show_request_to_go_live_checklist(
|
||||
)
|
||||
|
||||
mock_templates = mocker.patch(
|
||||
'app.models.service.Service.templates',
|
||||
'app.models.service.Service.all_templates',
|
||||
new_callable=PropertyMock,
|
||||
return_value=list(range(0, count_of_templates)),
|
||||
)
|
||||
|
||||
mock_templates_by_type = mocker.patch(
|
||||
'app.models.service.Service.templates_by_type',
|
||||
mock_get_templates = mocker.patch(
|
||||
'app.models.service.Service.get_templates',
|
||||
side_effect=_templates_by_type,
|
||||
)
|
||||
|
||||
@@ -598,7 +598,7 @@ def test_should_show_request_to_go_live_checklist(
|
||||
assert mock_templates.call_args_list == [
|
||||
call(),
|
||||
]
|
||||
assert mock_templates_by_type.call_args_list == [
|
||||
assert mock_get_templates.call_args_list == [
|
||||
call('email'),
|
||||
call('sms'),
|
||||
]
|
||||
@@ -683,12 +683,12 @@ def test_should_check_for_sms_sender_on_go_live(
|
||||
return_value=99,
|
||||
)
|
||||
mock_templates = mocker.patch(
|
||||
'app.models.service.Service.templates',
|
||||
'app.models.service.Service.all_templates',
|
||||
new_callable=PropertyMock,
|
||||
side_effect=partial(_templates_by_type, 'all'),
|
||||
)
|
||||
mock_templates_by_type = mocker.patch(
|
||||
'app.models.service.Service.templates_by_type',
|
||||
mock_get_templates = mocker.patch(
|
||||
'app.models.service.Service.get_templates',
|
||||
side_effect=_templates_by_type,
|
||||
)
|
||||
|
||||
@@ -712,7 +712,7 @@ def test_should_check_for_sms_sender_on_go_live(
|
||||
assert mock_templates.call_args_list == [
|
||||
call(),
|
||||
]
|
||||
assert mock_templates_by_type.call_args_list == [
|
||||
assert mock_get_templates.call_args_list == [
|
||||
call('email'),
|
||||
call('sms'),
|
||||
]
|
||||
@@ -747,7 +747,7 @@ def test_should_check_for_mou_on_request_to_go_live(
|
||||
return_value=0,
|
||||
)
|
||||
mocker.patch(
|
||||
'app.models.service.Service.templates',
|
||||
'app.models.service.Service.all_templates',
|
||||
new_callable=PropertyMock,
|
||||
return_value=[],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user