From 1028e676357966d912a7cd100625584e254ebaa2 Mon Sep 17 00:00:00 2001 From: auslin-aot <99173163+auslin-aot@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:46:33 +0530 Subject: [PATCH 1/2] FWF-4077: [Bugfix] Allow hyphen in form title, path & ame --- .../src/formsflow_api/services/form_process_mapper.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/forms-flow-api/src/formsflow_api/services/form_process_mapper.py b/forms-flow-api/src/formsflow_api/services/form_process_mapper.py index 4cd2dff79..27d388ae2 100644 --- a/forms-flow-api/src/formsflow_api/services/form_process_mapper.py +++ b/forms-flow-api/src/formsflow_api/services/form_process_mapper.py @@ -738,15 +738,15 @@ def is_valid_field(cls, field: str, pattern: str) -> bool: @classmethod def validate_title_name_path(cls, title: str, path: str, name: str): """Validates the title, path, and name fields.""" - title_pattern = r"(?=.*[A-Za-z])[A-Za-z0-9 ]+" - path_name = r"(?=.*[A-Za-z])[A-Za-z0-9]+" + title_pattern = r"(?=.*[A-Za-z])^[A-Za-z0-9 ]+(-{1,}[A-Za-z0-9 ]+)*$" + path_name = r"(?=.*[A-Za-z])^[A-Za-z0-9]+(-{1,}[A-Za-z0-9]+)*$" invalid_fields = [] error_messages = { - "title": "Title: Only contain alphanumeric characters and spaces, and must include at least one letter.", - "path": "Path: Only contain alphanumeric characters, no spaces, and must include at least one letter.", - "name": "Name: Only contain alphanumeric characters, no spaces, and must include at least one letter.", + "title": "Title: Only contain alphanumeric characters, hyphens(not at the start or end), spaces, and must include at least one letter.", + "path": "Path: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces, and must include at least one letter.", + "name": "Name: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces, and must include at least one letter.", } # Validate title From 12727657a05360633299eca186f4d0c9e69fb9df Mon Sep 17 00:00:00 2001 From: auslin-aot <99173163+auslin-aot@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:12:47 +0530 Subject: [PATCH 2/2] FWF-4077: [Bugfix] Flake & test fix --- .../services/form_process_mapper.py | 10 +++++--- .../unit/api/test_form_process_mapper.py | 24 +++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/forms-flow-api/src/formsflow_api/services/form_process_mapper.py b/forms-flow-api/src/formsflow_api/services/form_process_mapper.py index 27d388ae2..61ed0e719 100644 --- a/forms-flow-api/src/formsflow_api/services/form_process_mapper.py +++ b/forms-flow-api/src/formsflow_api/services/form_process_mapper.py @@ -744,9 +744,12 @@ def validate_title_name_path(cls, title: str, path: str, name: str): invalid_fields = [] error_messages = { - "title": "Title: Only contain alphanumeric characters, hyphens(not at the start or end), spaces, and must include at least one letter.", - "path": "Path: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces, and must include at least one letter.", - "name": "Name: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces, and must include at least one letter.", + "title": "Title: Only contain alphanumeric characters, hyphens(not at the start or end), spaces," + "and must include at least one letter.", + "path": "Path: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces," + "and must include at least one letter.", + "name": "Name: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces," + "and must include at least one letter.", } # Validate title @@ -793,6 +796,7 @@ def validate_form_name_path_title(request, **kwargs): name = request.args.get("name") path = request.args.get("path") form_id = request.args.get("id") + current_app.logger.info(f"Title:{title}, Name:{name}, Path:{path}") # Check if at least one query parameter is provided if not (title or name or path): diff --git a/forms-flow-api/tests/unit/api/test_form_process_mapper.py b/forms-flow-api/tests/unit/api/test_form_process_mapper.py index 3d0c5c1bb..a5910cb4c 100644 --- a/forms-flow-api/tests/unit/api/test_form_process_mapper.py +++ b/forms-flow-api/tests/unit/api/test_form_process_mapper.py @@ -573,7 +573,7 @@ def test_form_name_invalid_form_title(app, client, session, jwt, mock_redis_clie assert response.json is not None assert ( response.json["message"] - == "Title: Only contain alphanumeric characters and spaces, and must include at least one letter." + == "Title: Only contain alphanumeric characters, hyphens(not at the start or end), spaces,and must include at least one letter." ) # With special characters response = client.get("/form/validate?title=$$", headers=headers) @@ -581,14 +581,14 @@ def test_form_name_invalid_form_title(app, client, session, jwt, mock_redis_clie assert response.json is not None assert ( response.json["message"] - == "Title: Only contain alphanumeric characters and spaces, and must include at least one letter." + == "Title: Only contain alphanumeric characters, hyphens(not at the start or end), spaces,and must include at least one letter." ) response = client.get("/form/validate?title=1234$@@#test", headers=headers) assert response.status_code == 400 assert response.json is not None assert ( response.json["message"] - == "Title: Only contain alphanumeric characters and spaces, and must include at least one letter." + == "Title: Only contain alphanumeric characters, hyphens(not at the start or end), spaces,and must include at least one letter." ) @@ -602,7 +602,7 @@ def test_form_name_invalid_form_name(app, client, session, jwt, mock_redis_clien assert response.json is not None assert ( response.json["message"] - == "Name: Only contain alphanumeric characters, no spaces, and must include at least one letter." + == "Name: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces,and must include at least one letter." ) # With special characters response = client.get("/form/validate?name=1234", headers=headers) @@ -610,7 +610,7 @@ def test_form_name_invalid_form_name(app, client, session, jwt, mock_redis_clien assert response.json is not None assert ( response.json["message"] - == "Name: Only contain alphanumeric characters, no spaces, and must include at least one letter." + == "Name: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces,and must include at least one letter." ) # With spaces response = client.get("/form/validate?name=test form", headers=headers) @@ -618,7 +618,7 @@ def test_form_name_invalid_form_name(app, client, session, jwt, mock_redis_clien assert response.json is not None assert ( response.json["message"] - == "Name: Only contain alphanumeric characters, no spaces, and must include at least one letter." + == "Name: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces,and must include at least one letter." ) @@ -632,7 +632,7 @@ def test_form_name_invalid_form_path(app, client, session, jwt, mock_redis_clien assert response.json is not None assert ( response.json["message"] - == "Path: Only contain alphanumeric characters, no spaces, and must include at least one letter." + == "Path: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces,and must include at least one letter." ) # With special characters response = client.get("/form/validate?path=1234", headers=headers) @@ -640,7 +640,7 @@ def test_form_name_invalid_form_path(app, client, session, jwt, mock_redis_clien assert response.json is not None assert ( response.json["message"] - == "Path: Only contain alphanumeric characters, no spaces, and must include at least one letter." + == "Path: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces,and must include at least one letter." ) # With spaces response = client.get("/form/validate?path=test form", headers=headers) @@ -648,7 +648,7 @@ def test_form_name_invalid_form_path(app, client, session, jwt, mock_redis_clien assert response.json is not None assert ( response.json["message"] - == "Path: Only contain alphanumeric characters, no spaces, and must include at least one letter." + == "Path: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces,and must include at least one letter." ) @@ -667,7 +667,7 @@ def test_form_name_invalid_form_name_title_path( assert response.json is not None assert ( response.json["message"] - == """Title: Only contain alphanumeric characters and spaces, and must include at least one letter.,\n Path: Only contain alphanumeric characters, no spaces, and must include at least one letter.""" + == """Title: Only contain alphanumeric characters, hyphens(not at the start or end), spaces,and must include at least one letter.,\n Path: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces,and must include at least one letter.""" ) # Invalid name, title response = client.get( @@ -677,7 +677,7 @@ def test_form_name_invalid_form_name_title_path( assert response.json is not None assert ( response.json["message"] - == """Title: Only contain alphanumeric characters and spaces, and must include at least one letter.,\n Name: Only contain alphanumeric characters, no spaces, and must include at least one letter.""" + == """Title: Only contain alphanumeric characters, hyphens(not at the start or end), spaces,and must include at least one letter.,\n Name: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces,and must include at least one letter.""" ) # Invalid path, name response = client.get( @@ -687,7 +687,7 @@ def test_form_name_invalid_form_name_title_path( assert response.json is not None assert ( response.json["message"] - == """Path: Only contain alphanumeric characters, no spaces, and must include at least one letter.,\n Name: Only contain alphanumeric characters, no spaces, and must include at least one letter.""" + == """Path: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces,and must include at least one letter.,\n Name: Only contain alphanumeric characters, hyphens(not at the start or end), no spaces,and must include at least one letter.""" )