mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 19:03:30 -05:00
Fix go-live checks ignoring nested templates
This is a very low impact bug since a user can always create such
templates after their service is live and not be subject to checks
we do before that point. Still, we may as well fix it.
The main benefit of this change is actually to contribute towards
moving methods like "get_templates" out of the Service class so
we can simplify and cache their results more effectively.
Note: I wanted to simplify the Service class further as the two
"has_" properties are only used once in the app code. Unfortunately
they are tightly coupled in one of the tests as well [^1].
[^1]: bef0382cca/tests/app/main/views/service_settings/test_service_settings.py (L1961-L1962)
This commit is contained in:
@@ -284,13 +284,19 @@ class Service(JSONModel, SortByNameMixin):
|
||||
))
|
||||
)
|
||||
|
||||
def has_templates_of_type(self, template_type):
|
||||
return any(
|
||||
template for template in self.all_templates
|
||||
if template['template_type'] == template_type
|
||||
)
|
||||
|
||||
@property
|
||||
def has_email_templates(self):
|
||||
return len(self.get_templates('email')) > 0
|
||||
return self.has_templates_of_type('email')
|
||||
|
||||
@property
|
||||
def has_sms_templates(self):
|
||||
return len(self.get_templates('sms')) > 0
|
||||
return self.has_templates_of_type('sms')
|
||||
|
||||
@property
|
||||
def intending_to_send_email(self):
|
||||
|
||||
@@ -267,29 +267,7 @@ def test_service_billing_details(purchase_order_number, expected_result):
|
||||
assert service.billing_details == expected_result
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_has_email_templates_includes_folders(
|
||||
mocker,
|
||||
service_one,
|
||||
mock_get_template_folders,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.service_api_client.get_service_templates',
|
||||
return_value={'data': [create_template(
|
||||
folder='something', template_type='email'
|
||||
)]}
|
||||
)
|
||||
|
||||
mocker.patch(
|
||||
'app.template_folder_api_client.get_template_folders',
|
||||
return_value=[create_folder(id='something')]
|
||||
)
|
||||
|
||||
assert Service(service_one).has_email_templates
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_has_sms_templates_includes_folders(
|
||||
def test_has_templates_of_type_includes_folders(
|
||||
mocker,
|
||||
service_one,
|
||||
mock_get_template_folders,
|
||||
@@ -306,4 +284,4 @@ def test_has_sms_templates_includes_folders(
|
||||
return_value=[create_folder(id='something')]
|
||||
)
|
||||
|
||||
assert Service(service_one).has_sms_templates
|
||||
assert Service(service_one).has_templates_of_type('sms')
|
||||
|
||||
Reference in New Issue
Block a user