Skip to content

Commit

Permalink
fix-_check_only_lower_case_numbers_periods_hyphens_rule (#8715)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Osypenko <[email protected]>
  • Loading branch information
DanielOsypenko authored Nov 13, 2023
1 parent bade0e7 commit 41418ab
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ocs_ci/ocs/ui/page_objects/data_foundation_tabs_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,26 @@ def _check_only_lower_case_numbers_periods_hyphens_rule(self, rule_exp) -> bool:
Returns:
bool: indicating whether all test cases passed.
"""
allowed_chars = string.ascii_lowercase + string.digits + "-"

def replace_consecutive_symbols(text, symbol):
# Use regular expression to match consecutive symbols and replace them
pattern = rf"({re.escape(symbol)}+)" # Escape the symbol for safe use in the regex
return re.sub(
pattern,
lambda match: str(len(match.group(0)))
if len(match.group(0)) > 1
else match.group(0)[0],
text,
)

allowed_chars = string.ascii_lowercase + string.digits + "-."
allowed_chars = replace_consecutive_symbols(allowed_chars, "-")
allowed_chars = replace_consecutive_symbols(allowed_chars, ".")

random_name = "".join(random.choices(allowed_chars, k=10))
random_name = "a" + random_name + "z"
name_with_consecutive_period = random_name[:4] + ".." + random_name[6:]
name_with_consecutive_hyphen = random_name[:4] + "--" + random_name[6:]

uppercase_letters = "".join(random.choices(string.ascii_uppercase, k=2))
name_with_uppercase_letters = (
Expand All @@ -380,6 +395,7 @@ def _check_only_lower_case_numbers_periods_hyphens_rule(self, rule_exp) -> bool:
(rule_exp, name_with_consecutive_period, self.status_error),
(rule_exp, name_with_uppercase_letters, self.status_error),
(rule_exp, name_with_no_ascii, self.status_error),
(rule_exp, name_with_consecutive_hyphen, self.status_error),
(rule_exp, random_name, self.status_success),
]

Expand Down

0 comments on commit 41418ab

Please sign in to comment.