Ejemplo n.º 1
0
def test_http_download():
    mock = util.MockHTTPHandler()
    util.setup_urllib_mock(mock)
    p = util.tmppath()

    sy.net.download('http://www', p)

    eq_(sy.path.slurp(p), 'mock file')
Ejemplo n.º 2
0
def test_bad_target():
    mock = util.MockHTTPHandler()
    util.setup_urllib_mock(mock)

    try:
        sy.net.download('http://www', '/tmp')
        assert False, 'Specifying a dir should fail'
    except IOError:
        pass
Ejemplo n.º 3
0
def test_nonexistant_url():
    mock = util.MockHTTPHandler(mock_url = 'http://xxx')
    util.setup_urllib_mock(mock)
    p = util.tmppath()

    try:                              
        sy.net.download('http://www', p)
        assert False, 'Download bad url should fail'
    except urllib2.HTTPError:
        pass
Ejemplo n.º 4
0
def test_bad_url():
    def urlerror(req):
        raise urllib2.URLError('no host given')

    mock = util.MockHTTPHandler(resp_func=urlerror)
    util.setup_urllib_mock(mock)
    p = util.tmppath()

    try:
        sy.net.download('http:/www', p)
        assert False, 'Bad url should fail'
    except urllib2.URLError:
        pass