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