From 4b7846ae4a239c19858770ef678b8e60d617310d Mon Sep 17 00:00:00 2001 From: zhurong Date: Sat, 19 Dec 2015 00:23:28 +0800 Subject: [PATCH] Remove environment name restrictions Since we don't use environments and environment templates names during deployment process we don't need to check what is the name of the environment. Now we should only keep it human-readable and check that it exists. Change-Id: I2d665b41deebf0c008d8b2b71802a1ab2c6673e8 Closes-Bug: #1405788 --- muranodashboard/environments/forms.py | 21 +++++----- muranodashboard/environments/tables.py | 6 +-- muranodashboard/tests/functional/base.py | 2 +- muranodashboard/tests/functional/consts.py | 2 +- .../tests/functional/sanity_check.py | 39 +++++++++++++++++++ .../notes/bug-1405788-2c8b2708e3bfc63f.yaml | 4 ++ 6 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 releasenotes/notes/bug-1405788-2c8b2708e3bfc63f.yaml diff --git a/muranodashboard/environments/forms.py b/muranodashboard/environments/forms.py index 7d314293f..56d79d7a2 100644 --- a/muranodashboard/environments/forms.py +++ b/muranodashboard/environments/forms.py @@ -13,7 +13,6 @@ # under the License. import ast -from django.core import validators from django import forms from django.utils.translation import ugettext_lazy as _ from horizon import exceptions @@ -26,18 +25,15 @@ from muranodashboard.common import net from muranodashboard.environments import api LOG = logging.getLogger(__name__) -NAME_VALIDATORS = [validators.RegexValidator('^[a-zA-Z]+[\w.-]*$')] -ENV_NAME_HELP_TEXT = _("Environment names must contain only " - "alphanumeric or '_-.' characters " - "and must start with alpha") +ENV_NAME_HELP_TEXT = _("Environment name must contain at least one " + "non-white space symbol.") class CreateEnvironmentForm(horizon_forms.SelfHandlingForm): name = forms.CharField(label="Environment Name", - validators=NAME_VALIDATORS, - error_messages={'invalid': ENV_NAME_HELP_TEXT}, help_text=ENV_NAME_HELP_TEXT, - max_length=255) + max_length=255, + required=True) net_config = forms.ChoiceField( label=_("Environment Default Network"), @@ -57,6 +53,13 @@ class CreateEnvironmentForm(horizon_forms.SelfHandlingForm): self.fields['net_config'].choices = net_choices self.fields['net_config'].help_text = help_text + def clean_name(self): + cleaned_data = super(CreateEnvironmentForm, self).clean() + env_name = cleaned_data.get('name') + if not env_name.strip(): + self._errors['name'] = self.error_class([ENV_NAME_HELP_TEXT]) + return env_name + def handle(self, request, data): try: net_config = ast.literal_eval(data.pop('net_config')) @@ -65,7 +68,7 @@ class CreateEnvironmentForm(horizon_forms.SelfHandlingForm): env = api.environment_create(request, data) request.session['env_id'] = env.id messages.success(request, - 'Created environment "{0}"'.format(data['name'])) + u'Created environment "{0}"'.format(data['name'])) return True except exc.HTTPConflict: msg = _('Environment with specified name already exists') diff --git a/muranodashboard/environments/tables.py b/muranodashboard/environments/tables.py index cfe281a94..34931364a 100644 --- a/muranodashboard/environments/tables.py +++ b/muranodashboard/environments/tables.py @@ -33,7 +33,6 @@ from muranodashboard.api import packages as pkg_api from muranodashboard.catalog import views as catalog_views from muranodashboard.environments import api from muranodashboard.environments import consts -from muranodashboard.environments import forms as env_forms from muranodashboard.packages import consts as pkg_consts @@ -304,10 +303,7 @@ class EnvironmentsTable(tables.DataTable): name = tables.Column('name', link='horizon:murano:environments:services', verbose_name=_('Name'), - form_field=forms.CharField( - validators=env_forms.NAME_VALIDATORS, - error_messages={'invalid': - env_forms.ENV_NAME_HELP_TEXT},), + form_field=forms.CharField(), update_action=UpdateName, truncate=40) diff --git a/muranodashboard/tests/functional/base.py b/muranodashboard/tests/functional/base.py index 5699794af..f7eee8aee 100644 --- a/muranodashboard/tests/functional/base.py +++ b/muranodashboard/tests/functional/base.py @@ -177,7 +177,7 @@ class UITestCase(BaseDeps): self.driver.find_element(method, value) except (exc.NoSuchElementException, exc.ElementNotVisibleException): present = False - self.assertFalse(present, "Element {0} is preset on the page" + self.assertFalse(present, u"Element {0} is preset on the page" " while it should't".format(value)) self.driver.implicitly_wait(30) diff --git a/muranodashboard/tests/functional/consts.py b/muranodashboard/tests/functional/consts.py index 9cd9ccfc4..f24d78a8a 100644 --- a/muranodashboard/tests/functional/consts.py +++ b/muranodashboard/tests/functional/consts.py @@ -8,7 +8,7 @@ HotPackageDir = os.path.join(os.path.dirname(os.path.realpath(__file__)), CategorySelector = "//a[contains(text(), '{0}')][contains(@class, 'dropdown-toggle')]" # noqa App = "//div[contains(@class, 'app-list')]//h4[contains(text(), '{0}')]" MockAppDescr = "//div[h4[contains(text(), 'MockApp')]]/p" -AppPackages = "//tr[@data-display='{0}']" +AppPackages = u"//tr[@data-display='{0}']" TagInDetails = "//div[contains(@class, 'app-meta')]//ul//li[strong[contains(text(), 'Tags')]]" # noqa TestImage = "//tr[td[contains(text(), '{0}')]]" DeleteImageMeta = TestImage + "//td//button[contains(text(), 'Delete Metadata')]" # noqa diff --git a/muranodashboard/tests/functional/sanity_check.py b/muranodashboard/tests/functional/sanity_check.py index 84a3ac360..7af49d99c 100644 --- a/muranodashboard/tests/functional/sanity_check.py +++ b/muranodashboard/tests/functional/sanity_check.py @@ -99,6 +99,45 @@ class TestSuiteEnvironment(base.ApplicationTestCase): by.By.XPATH, "//div[@id='environment_switcher']/a[contains(text(), 'TestEnv')]") + def test_create_and_delete_environment_with_unicode_name(self): + """Test check ability to create and delete environment with unicode name + + Scenario: + 1. Create environment with unicode name + 2. Navigate to this environment + 3. Go back to environment list and delete created environment + """ + unicode_name = u'$yaql \u2665 unicode' + self.go_to_submenu('Environments') + self.create_environment(unicode_name) + self.go_to_submenu('Environments') + self.delete_environment(unicode_name) + self.check_element_not_on_page(by.By.LINK_TEXT, unicode_name) + + def test_check_env_name_validation(self): + """Test checks validation of field that usually define environment name + + Scenario: + 1. Navigate to Application Catalog > Environmentss + 2. Press 'Create environment' + 3. Check a set of names, if current name isn't valid + appropriate error message should appears + """ + self.go_to_submenu('Environments') + self.driver.find_element_by_css_selector(c.CreateEnvironment).click() + + self.driver.find_element_by_id(c.ConfirmCreateEnvironment).click() + error_message = 'This field is required.' + self.driver.find_element_by_xpath( + c.ErrorMessage.format(error_message)) + + self.fill_field(by.By.ID, 'id_name', ' ') + self.driver.find_element_by_id(c.ConfirmCreateEnvironment).click() + error_message = ('Environment name must contain at least one ' + 'non-white space symbol.') + self.driver.find_element_by_xpath( + c.ErrorMessage.format(error_message)) + class TestSuiteImage(base.ImageTestCase): def test_rename_image(self): diff --git a/releasenotes/notes/bug-1405788-2c8b2708e3bfc63f.yaml b/releasenotes/notes/bug-1405788-2c8b2708e3bfc63f.yaml new file mode 100644 index 000000000..21f893155 --- /dev/null +++ b/releasenotes/notes/bug-1405788-2c8b2708e3bfc63f.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - It is now possible to use any symbols in + environments name.