def test_check(self): validator = inputs.URL(check=True, ip=True) assert validator('http://www.google.com' ) == 'http://www.google.com', 'Should check domain' # This test will fail on a network where this address is defined self.assert_bad_url( validator, 'http://this-domain-should-not-exist-xxx.aasxdd.ssdd.asd.sddsfddaa', 'Domain does not exists')
def test_excluded_domains(self, url): validator = inputs.URL(exclude=['example.com', 'www.example.com']) self.assert_bad_url(validator, url, 'Domain is not allowed')
def test_valid_excluded_domains(self, url): validator = inputs.URL(exclude=['example.com', 'www.example.com']) assert validator(url) == url
def test_invalid_restricted_domains(self, url): validator = inputs.URL(domains=['example.com', 'www.example.com']) self.assert_bad_url(validator, url, 'Domain is not allowed')
def test_valid_restricted_domains(self, url): validator = inputs.URL(domains=['example.com', 'www.example.com']) assert validator(url) == url
def test_invalid_restricted_schemes(self, url): validator = inputs.URL(schemes=('sip', 'irc')) self.assert_bad_url(validator, url, 'Protocol is not allowed')
def test_valid_restricted_schemes(self, url): validator = inputs.URL(schemes=('sip', 'irc')) assert validator(url) == url
def test_bad_urls(self, url): # Test with everything enabled to ensure bad URL are really detected validator = inputs.URL(ip=True, auth=True, port=True) self.assert_bad_url(validator, url)
def test_reject_port(self, url): # Test with auth and port to ensure only port is rejected validator = inputs.URL(ip=True, auth=True) self.assert_bad_url(validator, url, 'Custom port is not allowed')
def test_allow_local(self, url): validator = inputs.URL(ip=True, local=True) assert validator(url) == url
def test_reject_local(self, url): # Test with IP and port to ensure only auth is rejected validator = inputs.URL(ip=True) self.assert_bad_url(validator, url, 'Localhost is not allowed')
def test_allow_auth(self, url): validator = inputs.URL(auth=True) assert validator(url) == url
def test_reject_auth(self, url): # Test with IP and port to ensure only auth is rejected validator = inputs.URL(ip=True, port=True) self.assert_bad_url(validator, url, 'Authentication is not allowed')
def test_reject_ip(self, url): validator = inputs.URL() self.assert_bad_url(validator, url, 'IP is not allowed')
def test_bad_urls_with_suggestion(self, url): validator = inputs.URL() self.assert_bad_url(validator, url, 'Did you mean: http://{0}')
def test_allow_port(self, url): validator = inputs.URL(port=True) assert validator(url) == url
def test_schema(self): assert inputs.URL().__schema__ == {'type': 'string', 'format': 'url'}
def test_valid_values_default(self, url): validator = inputs.URL() assert validator(url) == url