Example #1
0
    def test_with(self):
        url = URL('http://www.example.com/path/to/file.exe?query?fragment')

        self.assertEqual(
            str(url.with_scheme('https')),
            'https://www.example.com/path/to/file.exe?query?fragment')
        self.assertEqual(str(url.with_netloc('localhost')),
                         'http://localhost/path/to/file.exe?query?fragment')
        self.assertEqual(
            str(url.with_userinfo('username', 'password')),
            'http://*****:*****@www.example.com/path/to/file.exe?query?fragment'
        )
        self.assertEqual(
            str(url.with_userinfo(None, None)),
            'http://www.example.com/path/to/file.exe?query?fragment')
        self.assertEqual(
            str(url.with_hostinfo('localhost', 8080)),
            'http://localhost:8080/path/to/file.exe?query?fragment')

        self.assertEqual(str(URL('http://example.com/base/') / 'path/to/file'),
                         'http://example.com/base/path/to/file')

        self.assertEqual(
            str(
                URL('http://example.com/path/?q') /
                URL('http://localhost/app/?q') / URL('to/content')),
            'http://localhost/app/to/content')
Example #2
0
    def test_with(self):
        url = URL('http://www.example.com/path/to/file.exe?query?fragment')

        self.assertEqual(str(url.with_scheme('https')), 'https://www.example.com/path/to/file.exe?query?fragment')
        self.assertEqual(str(url.with_netloc('localhost')), 'http://localhost/path/to/file.exe?query?fragment')
        self.assertEqual(str(url.with_userinfo('username', 'password')),
                         'http://*****:*****@www.example.com/path/to/file.exe?query?fragment')
        self.assertEqual(str(url.with_userinfo(None, None)), 'http://www.example.com/path/to/file.exe?query?fragment')
        self.assertEqual(str(url.with_hostinfo('localhost', 8080)),
                         'http://localhost:8080/path/to/file.exe?query?fragment')

        self.assertEqual(str(URL('http://example.com/base/') / 'path/to/file'), 'http://example.com/base/path/to/file')

        self.assertEqual(str(URL('http://example.com/path/?q') / URL('http://localhost/app/?q') / URL('to/content')),
                         'http://localhost/app/to/content')