Ejemplo n.º 1
0
    def test_fields(self):
        url = Purl('sftp://secure-site:123')
        assert url.protocol() == 'sftp://'
        assert url.hostname() == 'secure-site'
        assert url.port() == ':123'
        assert url.path() == None

        url = Purl('http://nada.com')
        assert url.protocol() == 'http://'
        assert url.hostname() == 'nada.com'
        assert url.port() == None
        assert url.path() == None

        url = Purl('file://filesys/somefile.png')
        assert url.protocol() == 'file://'
        assert url.hostname() == 'filesys'
        assert url.port() == None
        assert url.path() == '/somefile.png'

        expected = 'https://firehouse.com:3333/freedom'
        url = Purl('http://blank')
        assert str(
            url.protocol('https://').hostname('firehouse.com').path(
                '/freedom').port(':3333')) == expected
        assert str(url) == expected
Ejemplo n.º 2
0
    def test_invalid_fields(self):
        u = Purl('http://blank')

        with pytest.raises(InvalidUrlError):
            u.protocol('')
        with pytest.raises(InvalidUrlError):
            u.protocol('://')
        with pytest.raises(InvalidUrlError):
            u.protocol('abc')

        with pytest.raises(InvalidUrlError):
            u.hostname('')
        with pytest.raises(InvalidUrlError):
            u.hostname('abcd/123/546')
        with pytest.raises(InvalidUrlError):
            u.hostname('abcd:123')
        with pytest.raises(InvalidUrlError):
            u.hostname('abcd:abcd')

        with pytest.raises(InvalidUrlError):
            u.port('80')
        with pytest.raises(InvalidUrlError):
            u.port(':abcd')

        with pytest.raises(InvalidUrlError):
            u.path('abcd/123')
        with pytest.raises(InvalidUrlError):
            u.path('abcd/123/')