Пример #1
0
 def test_url_and_schemes(self):
     site = Site("Example",
                 url='https://www.example.com/',
                 allowed_schemes=['https'])
     self.assertFalse(site.matches_url(urlparse('http://example.com/foo')))
     self.assertTrue(
         site.matches_url(urlparse('https://www.example.com/foo')))
Пример #2
0
    def test_cannot_have_path(self):
        with self.assertRaises(ImproperlyConfigured):
            Site("Example", url='https://www.example.com/woo')

        with self.assertRaises(ImproperlyConfigured):
            Site("Example", url='https://www.example.com/?woo=yay')

        with self.assertRaises(ImproperlyConfigured):
            Site("Example", url='https://www.example.com/#hoopla')
Пример #3
0
 def test_hostnames_and_schemes(self):
     site = Site("Example",
                 allowed_schemes=['https', 'ftp'],
                 allowed_hostnames=['www.example.com', 'ftp.example.com'])
     self.assertTrue(
         site.matches_url(urlparse('https://ftp.example.com/foo')))
     self.assertFalse(
         site.matches_url(urlparse('http://www.example.com/foo')))
     self.assertTrue(site.matches_url(
         urlparse('ftp://www.example.com/foo')))
Пример #4
0
 def test_url_only(self):
     site = Site("Example", url='https://example.com/')
     self.assertTrue(site.matches_url(urlparse('http://example.com/foo')))
     self.assertTrue(
         site.matches_url(urlparse('https://www.example.com/foo')))
     self.assertFalse(site.matches_url(urlparse('ftp://example.com/foo')))
     self.assertFalse(
         site.matches_url(urlparse('http://www2.example.com/foo')))
Пример #5
0
 class ExampleLink2(UrlPattern):
     site = Site('Example', url='https://example.com/')
     pattern = '/<int>/?id=<str>'
Пример #6
0
 class ExampleLink1(UrlPattern):
     site = Site('Example', url='https://example.com/')
     pattern = '/index.php?first=<str>&second=<str>'