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')))
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')
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')))
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')))
class ExampleLink2(UrlPattern): site = Site('Example', url='https://example.com/') pattern = '/<int>/?id=<str>'
class ExampleLink1(UrlPattern): site = Site('Example', url='https://example.com/') pattern = '/index.php?first=<str>&second=<str>'