From d5f9bce3f3ed5653132d13ecba517fd2a0540f6b Mon Sep 17 00:00:00 2001 From: zhurong Date: Fri, 15 Apr 2016 16:05:06 -0400 Subject: [PATCH] Added a warning message if environment name is empty Adding required=False to the environment name form allows it to call update_cell when it has been left empty. Added logic to update_cell to check if the form is empty or contains only whitespace and issue a warning if true and only if the form in question is called 'name'. Change-Id: I60eb475574be7713807fd0f5548a64b1f8c890c7 Closes-Bug: #1571663 --- muranodashboard/environments/tables.py | 6 +++++- .../tests/functional/sanity_check.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/muranodashboard/environments/tables.py b/muranodashboard/environments/tables.py index 4971a9a99..c127f724a 100644 --- a/muranodashboard/environments/tables.py +++ b/muranodashboard/environments/tables.py @@ -331,6 +331,10 @@ class UpdateServiceRow(tables.Row): class UpdateName(tables.UpdateAction): def update_cell(self, request, datum, obj_id, cell_name, new_cell_value): try: + if not new_cell_value or new_cell_value.isspace(): + message = _("The environment name field cannot be empty.") + messages.warning(request, message) + raise ValueError(message) mc = api_utils.muranoclient(request) mc.environments.update(datum.id, name=new_cell_value) except exc.HTTPConflict: @@ -356,7 +360,7 @@ class EnvironmentsTable(tables.DataTable): name = tables.Column('name', link='horizon:murano:environments:services', verbose_name=_('Name'), - form_field=forms.CharField(), + form_field=forms.CharField(required=False), update_action=UpdateName, truncate=40) diff --git a/muranodashboard/tests/functional/sanity_check.py b/muranodashboard/tests/functional/sanity_check.py index 972ffbf20..035b733e8 100644 --- a/muranodashboard/tests/functional/sanity_check.py +++ b/muranodashboard/tests/functional/sanity_check.py @@ -83,6 +83,23 @@ class TestSuiteEnvironment(base.ApplicationTestCase): self.check_element_on_page(by.By.LINK_TEXT, 'edited_env') self.check_element_not_on_page(by.By.LINK_TEXT, 'test_edit_env') + def test_edit_environment_to_empty(self): + """Test gives warning message if change environment name to empty + + Scenario: + 1. Create environment + 2. Change environment's name to empty + 3. Check warning message appear + """ + self.go_to_submenu('Environments') + self.create_environment('test_edit_env') + self.go_to_submenu('Environments') + + self.edit_environment(old_name='test_edit_env', new_name='') + + warning_message = 'The environment name field cannot be empty.' + self.check_alert_message(warning_message) + def test_create_env_from_the_catalog_page(self): """Test create environment from the catalog page