def test_validate_description_too_long(self): """ Assumptions: - given description have 61 length """ desc = "a" * 61 with self.assertRaisesRegex(ServerDescriptionNotValidError, "wrong length"): ServerOp.validate_description(desc)
def test_validate_description_not_string(self): """ Assumptions: - given description is not string (int instead) """ desc = 111 with self.assertRaisesRegex(ServerDescriptionNotValidError, "must be String"): ServerOp.validate_description(desc)
def test_validate_description_positive(self): """ Assumptions: - given description is string with length >= 1 and <= 60 and matched regex [A-Za-z0-9_]+ """ desc = "aA09_" try: ServerOp.validate_description(desc) except ServerDescriptionNotValidError: self.fail("ServerDescriptionNotValidError raised.")
def test_validate_description_wrong_characters(self): """ Assumptions: - given description does not match regex [A-Za-z0-9_ ]+ """ name_regex = r"[A-Za-z0-9_ ]+" wrong_chars = [ char for char in list(string.printable) if not re.match(name_regex, char) ] for wrong_char in wrong_chars: with self.assertRaisesRegex(ServerDescriptionNotValidError, "does not match regex"): ServerOp.validate_description(wrong_char)