def test_rejects_invalid_hostname(self): input = "%s abc-.foo" % factory.make_hostname() error = self.assertRaises( ValidationError, HostListFormField().clean, input) self.assertThat(error.message, Equals( "Invalid hostname: Label cannot start or end with " "hyphen: 'abc-'."))
def test_rejects_invalid_ipv6_address(self): input = "%s fe80::abcde" % factory.make_hostname() error = self.assertRaises(ValidationError, HostListFormField().clean, input) self.assertThat( error.message, Equals("Failed to detect a valid IP address from 'fe80::abcde'."))
def test_accepts_misc(self): servers = { "::1", "1::", "1::2", "1:2::3", "1::2:3", "1:2::3:4", "::127.0.0.1", } input = ",".join(servers) self.assertEqual(" ".join(servers), HostListFormField().clean(input))
def test_accepts_comma_separated_hostnames(self): hostnames = factory.make_hostname(), factory.make_hostname() input = ",".join(hostnames) self.assertEqual(" ".join(hostnames), HostListFormField().clean(input))
def test_accepts_hostname(self): hostname = factory.make_hostname() self.assertEqual(hostname, HostListFormField().clean(hostname))
def test_accepts_comma_separated_ips(self): ips = [factory.make_ip_address() for _ in range(5)] input = ",".join(ips) self.assertEqual(" ".join(ips), HostListFormField().clean(input))
def test_accepts_single_ip(self): ip = factory.make_ip_address() self.assertEqual(ip, HostListFormField().clean(ip))
def test_accepts_none(self): self.assertIsNone(HostListFormField().clean(None))
def test_accepts_space_separated_hostnames(self): hostnames = factory.make_hostname(), factory.make_hostname() input = ' '.join(hostnames) self.assertEqual(input, HostListFormField().clean(input))