-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
61 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from tracardi.process_engine.action.v1.interest.utils import is_valid_string | ||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def is_valid_string(variable): | ||
""" | ||
Check if the variable is a string composed of alphanumeric characters, underscores (_), and hyphens (-), | ||
contains no spaces, and has at least one alphanumeric character. | ||
Args: | ||
variable (str): The variable to be checked. | ||
Returns: | ||
bool: True if the variable meets the criteria, False otherwise. | ||
""" | ||
if not isinstance(variable, str): | ||
return False | ||
|
||
# Check for at least one alphanumeric character | ||
if not any(char.isalnum() for char in variable): | ||
return False | ||
|
||
# Checking if all characters are alphanumeric, underscore, or hyphen, and if there are no spaces | ||
return all(char.isalnum() or char in ['_', '-'] for char in variable) and ' ' not in variable | ||
|