Exemplo n.º 1
0
 def test_not_start_with_allow_all_schemes(self):
     URLValidator2(allow_schemes=("svn", ))("svn://domain.tld")
     try:
         URLValidator2(allow_schemes=("http", "ftp"))("svn://domain.tld")
     except ValidationError as err:
         self.assertEqual(six.text_type(err.message),
                          "The URL doesn't start with a allowed scheme.")
Exemplo n.º 2
0
 def test_not_start_with_allow_all_schemes(self):
     URLValidator2(allow_schemes=("svn", ))("svn://domain.test")
     try:
         URLValidator2(allow_schemes=("http", "ftp"))("svn://domain.test")
     except ValidationError as err:
         assert_pformat_equal(
             str(err.message),
             "The URL doesn't start with a allowed scheme.")
Exemplo n.º 3
0
 def test_only_local_path1(self):
     validator = URLValidator2(allow_schemes=None, allow_netloc=False)
     validator("/path/?query#fragment")
     try:
         validator("http://domain.test/path/?query#fragment")
     except ValidationError as err:
         assert_pformat_equal(six.text_type(err.message), "Please enter a local URL (without protocol/domain).")
Exemplo n.º 4
0
 def test_allow_fragment(self):
     validator = URLValidator2(allow_fragment=False)
     validator("http://www.domain.test/without/fragment/")
     try:
         validator("http://www.domain.test/with/a/#fragment")
     except ValidationError as err:
         assert_pformat_equal(six.text_type(err.message), "Enter a valid URL without a fragment.")
Exemplo n.º 5
0
 def test_allow_query(self):
     validator = URLValidator2(allow_query=False)
     validator("http://www.domain.test/without/query/")
     try:
         validator("http://www.domain.test/with/?query")
     except ValidationError as err:
         assert_pformat_equal(six.text_type(err.message), "Enter a valid URL without a query.")
Exemplo n.º 6
0
    def __init__(self,
                 verbose_name=None,
                 name=None,
                 verify_exists=True,
                 allow_schemes=("http", "https"),
                 allow_all_schemes=False,
                 allow_netloc=True,
                 allow_query=True,
                 allow_fragment=True,
                 **kwargs):

        kwargs['max_length'] = kwargs.get('max_length', 200)
        OriginModelCharField.__init__(self, verbose_name, name, **kwargs)

        self.allow_schemes = allow_schemes or ()
        self.allow_all_schemes = allow_all_schemes
        self.allow_netloc = allow_netloc
        self.allow_query = allow_query
        self.allow_fragment = allow_fragment

        self.validators.append(
            URLValidator2(allow_schemes=allow_schemes,
                          allow_all_schemes=allow_all_schemes,
                          allow_netloc=allow_netloc,
                          allow_query=allow_query,
                          allow_fragment=allow_fragment))
Exemplo n.º 7
0
 def test_no_allow_all_schemes(self):
     try:
         URLValidator2(allow_schemes=("http", "ftp"),
                       allow_all_schemes=True)
     except Warning as err:
         self.assertEqual(
             str(err),
             "allow_schemes would be ignored, while allow_all_schemes==True!"
         )
Exemplo n.º 8
0
 def test_only_local_path2(self):
     """
     **Note:** Validating the network location (netloc):
     Following the syntax specifications in RFC 1808, urlparse recognizes a
     netloc only if it is properly introduced by '//'. Otherwise the input is
     presumed to be a relative URL and thus to start with a path component.
     See: http://docs.python.org/library/urlparse.html#urlparse.urlparse
     """
     validator = URLValidator2(allow_schemes=None, allow_netloc=False)
     validator("www.pylucid.org/path?query#fragment")
     try:
         validator("//www.pylucid.org/path?query#fragment")
     except ValidationError as err:
         assert_pformat_equal(six.text_type(err.message), "Please enter a local URL (without protocol/domain).")
Exemplo n.º 9
0
    def __init__(self,
                 max_length=None,
                 min_length=None,
                 verify_exists=False,
                 allow_schemes=("http", "https"),
                 allow_all_schemes=False,
                 allow_netloc=True,
                 allow_query=True,
                 allow_fragment=True,
                 **kwargs):

        super().__init__(max_length=max_length,
                         min_length=min_length,
                         **kwargs)

        self.validators.append(
            URLValidator2(allow_schemes=allow_schemes,
                          allow_all_schemes=allow_all_schemes,
                          allow_netloc=allow_netloc,
                          allow_query=allow_query,
                          allow_fragment=allow_fragment))
Exemplo n.º 10
0
    def __init__(self,
                 max_length=None,
                 min_length=None,
                 verify_exists=False,
                 allow_schemes=("http", "https"),
                 allow_all_schemes=False,
                 allow_netloc=True,
                 allow_query=True,
                 allow_fragment=True,
                 validator_user_agent=validators.URL_VALIDATOR_USER_AGENT,
                 *args,
                 **kwargs):

        super(URLFormField2, self).__init__(max_length, min_length, *args,
                                            **kwargs)

        self.validators.append(
            URLValidator2(verify_exists=verify_exists,
                          allow_schemes=allow_schemes,
                          allow_all_schemes=allow_all_schemes,
                          allow_netloc=allow_netloc,
                          allow_query=allow_query,
                          allow_fragment=allow_fragment,
                          validator_user_agent=validator_user_agent))
Exemplo n.º 11
0
 def test_scheme_without_netloc(self):
     try:
         URLValidator2(allow_all_schemes=True, allow_netloc=False)
     except AssertionError as err:
         self.assertEqual(str(err), "Can't allow schemes without netloc!")