def test_utils_is_valid_hostname_invalid(self): """Verify is_valid_hostname can detect None or too-long hostnames""" # A hostname that's empty, None, or more than 255 chars is invalid empty_hostname = '' res = is_valid_hostname(empty_hostname) self.assertFalse(res) none_hostname = None res = is_valid_hostname(none_hostname) self.assertFalse(res) too_long_hostname = "a" * 256 res = is_valid_hostname(too_long_hostname) self.assertFalse(res)
def test_utils_is_valid_hostname_normal_hostname(self): """Verify is_valid_hostname can parse regular hostnames""" hostname = "foo.example.com" res = is_valid_hostname(hostname) self.assertTrue(res)
def test_utils_is_valid_hostname_ends_with_dot(self): """Verify is_valid_hostname can parse hostnames with trailing periods""" hostname = "foo.example.com." res = is_valid_hostname(hostname) self.assertTrue(res)
def validate_prompt_hostname(hostname): if hostname == '' or utils.is_valid_hostname(hostname): return hostname raise click.BadParameter('Invalid hostname. Please double-check this value and re-enter it.')
def validate_prompt_hostname(hostname): if hostname == '' or utils.is_valid_hostname(hostname): return hostname raise click.BadParameter( 'Invalid hostname. Please double-check this value and re-enter it.')