From fb223556cbf6083e2909cd4df693fc63aa9fa7e6 Mon Sep 17 00:00:00 2001 From: miloszowi Date: Fri, 8 Oct 2021 17:35:03 +0200 Subject: [PATCH] group name validation changed to accept all alphanumeric characters, fixed no groups reply --- src/repository/groupRepository.py | 2 +- src/validator/groupNameValidator.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/repository/groupRepository.py b/src/repository/groupRepository.py index 43832e0..004683f 100644 --- a/src/repository/groupRepository.py +++ b/src/repository/groupRepository.py @@ -50,7 +50,7 @@ class GroupRepository: Group(chat_id, group_name, group[self.count]) ) - if not groups: + if not result: raise NotFoundException return result diff --git a/src/validator/groupNameValidator.py b/src/validator/groupNameValidator.py index 3eca5e4..4c89902 100644 --- a/src/validator/groupNameValidator.py +++ b/src/validator/groupNameValidator.py @@ -4,13 +4,14 @@ from exception.invalidArgumentException import InvalidArgumentException class GroupNameValidator: + MAX_GROUP_NAME_LENGTH: int = 20 @staticmethod def validate(group: str) -> None: group = group.lower() - if len(group) > 0 and not re.match(r"^[A-Za-z]+$", group): - raise InvalidArgumentException(re.escape('Group name must contain only letters.')) + if len(group) > 0 and not re.match('^\w+$', group): + raise InvalidArgumentException(re.escape('Special characters are not allowed.')) - if len(group) > 20: - raise InvalidArgumentException(re.escape(f'Group name length can not be greater than 20.')) + if len(group) > GroupNameValidator.MAX_GROUP_NAME_LENGTH: + raise InvalidArgumentException(re.escape(f'Group name length can not be greater than {GroupNameValidator.MAX_GROUP_NAME_LENGTH}.'))