Esempio n. 1
0
def test_get_file_from_url_overwrite_file_exists(httpserver, tmpdir):
    httpserver.serve_content('nothing')
    url = httpserver.url
    name = url.split('/')[-1]
    # create the file
    p = tmpdir.join(name)
    p.write('something')
    assert p.read() == 'something'
    # get the file
    path = get_file_from_url(url, str(tmpdir), True)
    # check
    assert p.read() == 'nothing'
    assert str(p) == path
Esempio n. 2
0
def test_get_file_from_url_no_overwrite_file_exists(httpserver, tmpdir):
    httpserver.serve_content('nothing')
    url = httpserver.url
    name = url.split('/')[-1]
    # create the file
    p = tmpdir.join(name)
    p.write('something')
    assert p.read() == 'something'
    # get the file
    fl = get_file_from_url(url, str(tmpdir))
    # assert a new file was created
    assert p.read() == 'something'
    with open(fl, 'r') as recieved_data:
        assert recieved_data.read() == 'nothing'
Esempio n. 3
0
def test_get_file_from_url_no_overwrite_file_does_not_exist(httpserver, tmpdir):
    httpserver.serve_content('nothing')
    url = httpserver.url
    path = get_file_from_url(url, str(tmpdir), False)
    name = url.split('/')[-1]
    assert path == str(tmpdir) + '/' + name
Esempio n. 4
0
def test_get_file_from_url_folder_does_not_exist_no_overwrite(httpserver, tmpdir):
    httpserver.serve_content('nothing')
    url = httpserver.url
    folder = str(tmpdir) + '/random/'
    fl = get_file_from_url(url, folder)
    assert fl == str(tmpdir) + '/random/' + url.split('/')[-1]
Esempio n. 5
0
def test_get_file_from_url_unable_to_retrieve_url():
    url = 'http://example.com/some/exist.html'
    with pytest.raises(errors.InterfaceNotRunning):
        get_file_from_url(url, 'filename')