From da5dbc5bdda86cd04a16532f07d607e77d3f0754 Mon Sep 17 00:00:00 2001 From: richard-dds Date: Fri, 24 Aug 2018 13:15:27 -0400 Subject: [PATCH 1/8] Redirect to new project form after FV approval --- atst/routes/requests/financial_verification.py | 2 +- templates/workspace_project_new.html | 8 ++++++++ templates/workspace_projects.html | 9 --------- tests/routes/test_financial_verification.py | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/atst/routes/requests/financial_verification.py b/atst/routes/requests/financial_verification.py index 8c4e5666..29f5ce39 100644 --- a/atst/routes/requests/financial_verification.py +++ b/atst/routes/requests/financial_verification.py @@ -45,7 +45,7 @@ def update_financial_verification(request_id): new_workspace = Requests.approve_and_create_workspace(updated_request) return redirect( url_for( - "workspaces.workspace_projects", + "workspaces.new_project", workspace_id=new_workspace.id, newWorkspace=True, ) diff --git a/templates/workspace_project_new.html b/templates/workspace_project_new.html index b32178c7..dc19b669 100644 --- a/templates/workspace_project_new.html +++ b/templates/workspace_project_new.html @@ -9,6 +9,14 @@ {% block workspace_content %} {% set modalName = "newProjectConfirmation" %} +{% if request.args.get("newWorkspace") %} + {{ Alert('Workspace created!', + message="\ +

You are now ready to create projects and environments within the JEDI Cloud.

+ ", + level='success' + ) }} +{% endif %}
diff --git a/templates/workspace_projects.html b/templates/workspace_projects.html index cd2a1308..d2af0e17 100644 --- a/templates/workspace_projects.html +++ b/templates/workspace_projects.html @@ -5,15 +5,6 @@ {% block workspace_content %} -{% if request.args.get("newWorkspace") %} - {{ Alert('Workspace created!', - message="\ -

You are now ready to create projects and environments within the JEDI Cloud.

- ", - level='success' - ) }} -{% endif %} - {% for project in workspace.projects %}
diff --git a/tests/routes/test_financial_verification.py b/tests/routes/test_financial_verification.py index d3750ef2..673ee57d 100644 --- a/tests/routes/test_financial_verification.py +++ b/tests/routes/test_financial_verification.py @@ -137,4 +137,4 @@ class TestPENumberInForm: response = self.submit_data(client, data, extended=True) assert response.status_code == 302 - assert "/workspaces" in response.headers.get("Location") + assert "/projects/new" in response.headers.get("Location") From 66877b46bd3a143e1d66c449ca3851be03913541 Mon Sep 17 00:00:00 2001 From: richard-dds Date: Fri, 24 Aug 2018 13:49:39 -0400 Subject: [PATCH 2/8] Ensure that project environment names are unique --- atst/forms/new_project.py | 7 +++++-- atst/forms/validators.py | 9 +++++++++ tests/forms/test_validators.py | 17 ++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/atst/forms/new_project.py b/atst/forms/new_project.py index 65685e70..b6007364 100644 --- a/atst/forms/new_project.py +++ b/atst/forms/new_project.py @@ -1,7 +1,7 @@ from flask_wtf import Form from wtforms.fields import StringField, TextAreaField, FieldList from wtforms.validators import Required -from atst.forms.validators import ListItemRequired +from atst.forms.validators import ListItemRequired, ListItemsUnique class NewProjectForm(Form): @@ -12,7 +12,10 @@ class NewProjectForm(Form): description = TextAreaField(label="Description", validators=[Required()]) environment_names = FieldList( StringField(label="Environment Name"), - validators=[ListItemRequired(message="Provide at least one environment name.")], + validators=[ + ListItemRequired(message="Provide at least one environment name."), + ListItemsUnique(message="Environment names must be unique."), + ], ) @property diff --git a/atst/forms/validators.py b/atst/forms/validators.py index 5be056e3..1cc8bb83 100644 --- a/atst/forms/validators.py +++ b/atst/forms/validators.py @@ -60,3 +60,12 @@ def ListItemRequired(message="Please provide at least one.", empty_values=("", N raise ValidationError(message) return _list_item_required + + +def ListItemsUnique(message="Items must be unique"): + def _list_items_unique(form, field): + sorted_values = sorted(v for v in field.data) + if sorted_values != sorted(set(sorted_values)): + raise ValidationError(message) + + return _list_items_unique diff --git a/tests/forms/test_validators.py b/tests/forms/test_validators.py index 794310ac..4fc16412 100644 --- a/tests/forms/test_validators.py +++ b/tests/forms/test_validators.py @@ -1,7 +1,7 @@ from wtforms.validators import ValidationError import pytest -from atst.forms.validators import Alphabet, IsNumber, PhoneNumber +from atst.forms.validators import Alphabet, IsNumber, PhoneNumber, ListItemsUnique class TestIsNumber: @@ -51,3 +51,18 @@ class TestAlphabet: dummy_field.data = invalid with pytest.raises(ValidationError): validator(dummy_form, dummy_field) + + +class TestListItemsUnique: + @pytest.mark.parametrize("valid", [["a", "aa", "aaa"], ["one", "two", "three"]]) + def test_ListItemsUnique_allows_unique_items(self, valid, dummy_form, dummy_field): + validator = ListItemsUnique() + dummy_field.data = valid + validator(dummy_form, dummy_field) + + @pytest.mark.parametrize("invalid", [["a", "a", "a"], ["one", "two", "two", "three"]]) + def test_ListItemsUnique_rejects_non_letters(self, invalid, dummy_form, dummy_field): + validator = ListItemsUnique() + dummy_field.data = invalid + with pytest.raises(ValidationError): + validator(dummy_form, dummy_field) From 2d6ad1311b82d20796718eebcec50cc9df2c578d Mon Sep 17 00:00:00 2001 From: richard-dds Date: Fri, 24 Aug 2018 13:51:55 -0400 Subject: [PATCH 3/8] Display environment errors in project form --- templates/components/alert.html | 4 ++++ templates/workspace_project_new.html | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/components/alert.html b/templates/components/alert.html index 80f99196..1fa86489 100644 --- a/templates/components/alert.html +++ b/templates/components/alert.html @@ -31,6 +31,10 @@
{{ message | safe }}
{% endif %} + {% if caller %} +
{{ caller() }}
+ {% endif %} + {% if fragment %}
{% include fragment %} diff --git a/templates/workspace_project_new.html b/templates/workspace_project_new.html index dc19b669..f5304b4b 100644 --- a/templates/workspace_project_new.html +++ b/templates/workspace_project_new.html @@ -54,7 +54,11 @@
{% if form.environment_names.errors %} - {{ Alert("Missing Environments", message="Provide at least one environment name.", level="error") }} + {% call Alert("Missing Environments", level="error") %} + {% for error in form.environment_names.errors %} +

{{ error }}

+ {% endfor %} + {% endcall %} {% endif %}
From 9dcbb814de0cbb9207427ab791a60519d5b84605 Mon Sep 17 00:00:00 2001 From: richard-dds Date: Fri, 24 Aug 2018 13:55:14 -0400 Subject: [PATCH 4/8] Formatting --- tests/forms/test_validators.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/forms/test_validators.py b/tests/forms/test_validators.py index 4fc16412..c57a603d 100644 --- a/tests/forms/test_validators.py +++ b/tests/forms/test_validators.py @@ -60,8 +60,12 @@ class TestListItemsUnique: dummy_field.data = valid validator(dummy_form, dummy_field) - @pytest.mark.parametrize("invalid", [["a", "a", "a"], ["one", "two", "two", "three"]]) - def test_ListItemsUnique_rejects_non_letters(self, invalid, dummy_form, dummy_field): + @pytest.mark.parametrize( + "invalid", [["a", "a", "a"], ["one", "two", "two", "three"]] + ) + def test_ListItemsUnique_rejects_non_letters( + self, invalid, dummy_form, dummy_field + ): validator = ListItemsUnique() dummy_field.data = invalid with pytest.raises(ValidationError): From 9d16c6da5cd5dd4ec1c542ab093672701f652f01 Mon Sep 17 00:00:00 2001 From: richard-dds Date: Fri, 24 Aug 2018 14:18:58 -0400 Subject: [PATCH 5/8] Move tooltip copy inline --- styles/elements/_block_lists.scss | 7 +++++++ templates/workspace_project_new.html | 17 +++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/styles/elements/_block_lists.scss b/styles/elements/_block_lists.scss index f0549853..ac6936c0 100644 --- a/styles/elements/_block_lists.scss +++ b/styles/elements/_block_lists.scss @@ -18,7 +18,14 @@ .icon-tooltip { margin: -$gap; + } + &--grow { + display: inline-block; + width: 100%; + p { + margin-bottom: 0; + } } } diff --git a/templates/workspace_project_new.html b/templates/workspace_project_new.html index f5304b4b..d06b8270 100644 --- a/templates/workspace_project_new.html +++ b/templates/workspace_project_new.html @@ -40,14 +40,12 @@

Add a new project

- {{ Tooltip( - "AT-AT allows you to organize your workspace into multiple projects, each of which may have environments.", - title="learn more" - )}}
-
+

+ AT-AT allows you to organize your workspace into multiple projects, each of which may have environments. +

{{ TextInput(form.name) }} {{ TextInput(form.description, paragraph=True) }}
@@ -62,12 +60,11 @@ {% endif %}
-
+

Project Environments

- {{ Tooltip( - "Each environment created within a project is an enclave of cloud resources that is logically separated from each other for increased security.", - title="learn more" - )}} +

+ Each environment created within a project is an enclave of cloud resources that is logically separated from each other for increased security. +

    From 92080abe0a097715ca8bd214a63c6049355bea1a Mon Sep 17 00:00:00 2001 From: richard-dds Date: Fri, 24 Aug 2018 15:26:38 -0400 Subject: [PATCH 6/8] Rename test to be more accurate --- tests/forms/test_validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/forms/test_validators.py b/tests/forms/test_validators.py index c57a603d..3f3dd978 100644 --- a/tests/forms/test_validators.py +++ b/tests/forms/test_validators.py @@ -63,7 +63,7 @@ class TestListItemsUnique: @pytest.mark.parametrize( "invalid", [["a", "a", "a"], ["one", "two", "two", "three"]] ) - def test_ListItemsUnique_rejects_non_letters( + def test_ListItemsUnique_rejects_duplicate_names( self, invalid, dummy_form, dummy_field ): validator = ListItemsUnique() From 4cb2447edb3228bf0cc37428db7dd47385f6f6bd Mon Sep 17 00:00:00 2001 From: richard-dds Date: Fri, 24 Aug 2018 15:26:55 -0400 Subject: [PATCH 7/8] Simplify ListItemsUnique check --- atst/forms/validators.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/atst/forms/validators.py b/atst/forms/validators.py index 1cc8bb83..9d007ecf 100644 --- a/atst/forms/validators.py +++ b/atst/forms/validators.py @@ -64,8 +64,7 @@ def ListItemRequired(message="Please provide at least one.", empty_values=("", N def ListItemsUnique(message="Items must be unique"): def _list_items_unique(form, field): - sorted_values = sorted(v for v in field.data) - if sorted_values != sorted(set(sorted_values)): + if len(field.data) > len(set(field.data)): raise ValidationError(message) return _list_items_unique From 7145c36ed1143a2b3aa1baaae53c92747a3aeed2 Mon Sep 17 00:00:00 2001 From: richard-dds Date: Fri, 24 Aug 2018 16:01:23 -0400 Subject: [PATCH 8/8] Put error message in alert name --- templates/workspace_project_new.html | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/templates/workspace_project_new.html b/templates/workspace_project_new.html index d06b8270..71daf9cc 100644 --- a/templates/workspace_project_new.html +++ b/templates/workspace_project_new.html @@ -52,11 +52,9 @@
{% if form.environment_names.errors %} - {% call Alert("Missing Environments", level="error") %} - {% for error in form.environment_names.errors %} -

{{ error }}

- {% endfor %} - {% endcall %} + {% for error in form.environment_names.errors %} + {{ Alert(error, level="error") }} + {% endfor %} {% endif %}