Skip to content

Commit

Permalink
fix: update is_valid_string function and its tests
Browse files Browse the repository at this point in the history
- Modify is_valid_string to accept allowed_characters param
- Update tests in test_is_valid_string.py to reflect changes
- Add new test cases for additional allowed characters
  • Loading branch information
atompie committed Sep 18, 2024
1 parent e5b1917 commit f4b38db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 8 additions & 6 deletions test/unit/test_is_valid_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@


def test_alphanumeric():
assert is_valid_string("abc123") == True
assert is_valid_string("abc_123") == True
assert is_valid_string("abc-123") == True
assert is_valid_string("abc@123") == False
assert is_valid_string("___---") == False
assert is_valid_string("_") == False
assert is_valid_string("abc123") is True
assert is_valid_string("abc_123") is True
assert is_valid_string("abc-123") is True
assert is_valid_string("abc@123") is False
assert is_valid_string("___---") is False
assert is_valid_string("_") is False
assert is_valid_string("a,b,c") is True
assert is_valid_string("a,b, c") is False
5 changes: 3 additions & 2 deletions tracardi/process_engine/action/v1/interest/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def is_valid_string(variable):
def is_valid_string(variable, allowed_characters=None):
"""
Check if the variable is a string composed of alphanumeric characters, underscores (_),
hyphens (-), commas (,), and colons (:), contains no spaces, and has at least one alphanumeric character.
Expand All @@ -17,5 +17,6 @@ def is_valid_string(variable):
return False

# Checking if all characters are alphanumeric, underscore, hyphen, comma, or colon, and if there are no spaces
allowed_characters = ['_', '-', ',']
if allowed_characters is None:
allowed_characters = ['_', '-', ',']
return all(char.isalnum() or char in allowed_characters for char in variable) and ' ' not in variable

0 comments on commit f4b38db

Please sign in to comment.