From 7170723ba36da466e18f7d5391aeb6cf8eda5e2f Mon Sep 17 00:00:00 2001 From: Georg Osang Date: Wed, 19 Feb 2025 15:38:51 +0100 Subject: [PATCH] Enforce variable names start with a letter --- src/rpft/rapidpro/models/common.py | 4 ++-- tests/test_actions.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rpft/rapidpro/models/common.py b/src/rpft/rapidpro/models/common.py index 77a9997..f263695 100644 --- a/src/rpft/rapidpro/models/common.py +++ b/src/rpft/rapidpro/models/common.py @@ -100,9 +100,9 @@ def generate_field_key(field_name): {"length": len(key), "limit": FIELD_KEY_MAX_LENGTH, "key": key}, ) - if not re.search("[A-Za-z]", key): + if not re.match(r"^[a-z][a-z0-9_]*$", key): raise RapidProActionError( - "Contact field key without letter characters detected", + "Contact field key needs to start with a letter", {"key": key, "name": field_name}, ) diff --git a/tests/test_actions.py b/tests/test_actions.py index 7059ef3..4b83291 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -30,6 +30,6 @@ def test_fail_if_max_key_length_exceeded(self): with self.assertRaises(RapidProActionError): generate_field_key("z" * 37) - def test_fail_if_key_does_not_contain_letters(self): + def test_fail_if_key_does_not_start_with_letter(self): with self.assertRaises(RapidProActionError): - generate_field_key("123") + generate_field_key("1zx")