示例#1
0
    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')
示例#2
0
 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')
示例#3
0
 def test_valid_excluded_domains(self, url):
     validator = inputs.URL(exclude=['example.com', 'www.example.com'])
     assert validator(url) == url
示例#4
0
 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')
示例#5
0
 def test_valid_restricted_domains(self, url):
     validator = inputs.URL(domains=['example.com', 'www.example.com'])
     assert validator(url) == url
示例#6
0
 def test_invalid_restricted_schemes(self, url):
     validator = inputs.URL(schemes=('sip', 'irc'))
     self.assert_bad_url(validator, url, 'Protocol is not allowed')
示例#7
0
 def test_valid_restricted_schemes(self, url):
     validator = inputs.URL(schemes=('sip', 'irc'))
     assert validator(url) == url
示例#8
0
 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)
示例#9
0
 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')
示例#10
0
 def test_allow_local(self, url):
     validator = inputs.URL(ip=True, local=True)
     assert validator(url) == url
示例#11
0
 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')
示例#12
0
 def test_allow_auth(self, url):
     validator = inputs.URL(auth=True)
     assert validator(url) == url
示例#13
0
 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')
示例#14
0
 def test_reject_ip(self, url):
     validator = inputs.URL()
     self.assert_bad_url(validator, url, 'IP is not allowed')
示例#15
0
 def test_bad_urls_with_suggestion(self, url):
     validator = inputs.URL()
     self.assert_bad_url(validator, url, 'Did you mean: http://{0}')
示例#16
0
 def test_allow_port(self, url):
     validator = inputs.URL(port=True)
     assert validator(url) == url
示例#17
0
 def test_schema(self):
     assert inputs.URL().__schema__ == {'type': 'string', 'format': 'url'}
示例#18
0
 def test_valid_values_default(self, url):
     validator = inputs.URL()
     assert validator(url) == url