cdent / wsgi-intercept

Intercept socket connection to wsgi applications for testing
MIT License
42 stars 21 forks source link

When using the url arg to an Interceptor, if there is no port in the url an error happens #41

Closed cdent closed 8 years ago

cdent commented 8 years ago

This fails:

def test_intercept_by_url():
    hostname = str(uuid4())
    url = 'http://%s/foobar' % hostname
    interceptor = Httplib2Interceptor(app=app, url=url)
    assert isinstance(interceptor, Interceptor)
    assert interceptor.app == app
    assert interceptor.host == hostname
    assert interceptor.port == 80
    assert interceptor.script_name == '/foobar'
    assert interceptor.url == 'http://%s:%s/foobar' % (hostname, port)
    assert interceptor.url == url

with

wsgi_intercept/interceptor.py:35: in __init__
    self._init_from_url(url)
wsgi_intercept/interceptor.py:70: in _init_from_url
    host, port = parsed_url.netloc.split(':')
E   ValueError: need more than 1 value to unpack

Basically that split needs to be safer.