def testIsLinkIdFormatValid(self): """Tests the validity of Link Ids. """ #valid: starts with lowercase, no double underscores, does not end #with an underscore self.assertTrue(validate.isLinkIdFormatValid('sfd32')) #invalid: starts with a number self.assertFalse(validate.isLinkIdFormatValid('9s8whhu')) #invalid: starts with an underscore self.assertFalse(validate.isLinkIdFormatValid('_jhja87')) #valid: double underscore self.assertTrue(validate.isLinkIdFormatValid('kjnask__j87')) #valid: trailing underscore self.assertTrue(validate.isLinkIdFormatValid('jhsdfj_')) #invalid: starting and trailing underscores self.assertFalse(validate.isLinkIdFormatValid('_jhsj38_')) #invalid: starts with uppercase self.assertFalse(validate.isLinkIdFormatValid('Ukkjs')) #valid: underscore in the middle and rest in lowercase self.assertTrue(validate.isLinkIdFormatValid('a_b')) #invalid: a capital letter in the middle self.assertFalse(validate.isLinkIdFormatValid('aBc'))
def wrapper(self): """Decorator wrapped method. """ from soc.modules.gci.logic.models.mentor import logic as gci_mentor_logic mentors_list_str = cleaning.str2set(field_name)(self) fields = {"scope_path": self.cleaned_data.get("scope_path"), "status": "active"} mentors = [] for link_id in mentors_list_str: if not validate.isLinkIdFormatValid(link_id): raise forms.ValidationError("%s is not a valid link ID." % link_id) fields["link_id"] = link_id mentor = gci_mentor_logic.getFromKeyFields(fields) if not mentor: raise forms.ValidationError('link_id "%s" is not a valid Mentor.' % link_id) mentors.append(mentor.key()) return mentors
def wrapper(self): """Decorator wrapped method. """ from soc.modules.gci.logic.models.mentor import logic as gci_mentor_logic mentors_list_str = cleaning.str2set(field_name)(self) fields = { 'scope_path': self.cleaned_data.get('scope_path'), 'status': 'active' } mentors = [] for link_id in mentors_list_str: if not validate.isLinkIdFormatValid(link_id): raise forms.ValidationError( "%s is not a valid link ID." % link_id) fields['link_id'] = link_id mentor = gci_mentor_logic.getFromKeyFields(fields) if not mentor: raise forms.ValidationError( 'link_id "%s" is not a valid Mentor.' % link_id) mentors.append(mentor.key()) return mentors
def wrapper(self): """Decorator wrapper method. """ # convert to lowercase for user comfort link_id = self.cleaned_data.get(field_name).lower() if not validate.isLinkIdFormatValid(link_id): raise forms.ValidationError("This link ID is in wrong format.", code='invalid') return link_id
def cleanLinkID(link_id): """Validates that a string fits the form required of a link ID. Args: link_id: Any string. Raises: forms.ValidationError: The string does not fit the form required of a link ID. """ if not validate.isLinkIdFormatValid(link_id): raise forms.ValidationError( DEF_INVALID_LINK_ID % link_id, code=_INVALID_CODE)
def cleanLinkID(link_id): """Validates that a string fits the form required of a link ID. Args: link_id: Any string. Raises: forms.ValidationError: The string does not fit the form required of a link ID. """ if not validate.isLinkIdFormatValid(link_id): raise forms.ValidationError(DEF_INVALID_LINK_ID % link_id, code=_INVALID_CODE)
def testisLinkIdFormatValid(self): """Test the validity of Link Ids. """ # valid:starts with lowercase, no double underscores, does not end with an underscore self.assertTrue(validate.isLinkIdFormatValid('sfd32')) # invalid:starts with a number self.assertFalse(validate.isLinkIdFormatValid('9s8whhu')) # invalid:starts with an underscore self.assertFalse(validate.isLinkIdFormatValid('_jhja87')) # invalid: double underscore self.assertFalse(validate.isLinkIdFormatValid('kjnask__j87')) # invalid: trailing underscore self.assertFalse(validate.isLinkIdFormatValid('jhsdfj_')) # invalid: starting and trailing underscores self.assertFalse(validate.isLinkIdFormatValid('_jhsj38_')) # invalid: starts with uppercase self.assertFalse(validate.isLinkIdFormatValid('Ukkjs'))