예제 #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')
예제 #2
0
파일: test_url.py 프로젝트: jmcs/urlpath
    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')