Пример #1
0
def test_downloader_data_already_set_up(_tmp_dir, caplog):
    '''
    Testing if data is already set up, 
    meaning folder named 'test' already in download_dir
    '''
    if not os.path.exists(os.path.join(_tmp_dir.strpath, 'test')):
        os.mkdir(os.path.join(_tmp_dir.strpath, 'test'))
    d = Downloader('test', download_dir=_tmp_dir.strpath, url=URL_MODEL)
def test_downloader_data_already_set_up(_tmp_dir, caplog):
    '''
    Testing if data is already set up, 
    meaning folder named 'test' already in download_dir
    '''
    if not os.path.exists(os.path.join(_tmp_dir.strpath, 'test')):
        os.mkdir(os.path.join(_tmp_dir.strpath, 'test'))
    d = Downloader('test', download_dir=_tmp_dir.strpath, url=URL_MODEL)
    assert caplog.records[0].levelname == 'INFO'
    assert 'data already set up' in caplog.text
Пример #3
0
def test_downloader(mock_tarfile, mock_get, _tmp_dir):
    content_disposition = 'attachment; filename="model.tar.gz"; filename*=UTF-8''model.tar.gz'
    model_tarfile = tarfile.open(os.path.join(_tmp_dir.strpath, 'model.tar.gz'), 'r:gz')
    headers = {'content-disposition': content_disposition, 'content-length': 100000}
    mock_resp = _mock_response(headers=headers)
    mock_get.return_value = mock_resp
    mock_tarfile.open.return_value = model_tarfile 
    d = Downloader('test', download_dir=_tmp_dir.strpath, url=URL_MODEL)
    test_folder = os.path.join(_tmp_dir.strpath, 'test')
    m = os.path.join(test_folder, 'model')
    assert len(_tmp_dir.listdir()) == 2 #test folder, temp model tar
    f = io.open(m, mode='r', encoding='utf-8')
    #checking if untar model is the same as the one in _tmp_dir tar file
    assert str(f.read()) == 'TEST'
Пример #4
0
def test_downloader_failed(mock_get, _tmp_dir):
    mock_resp = _mock_response()
    mock_get.return_value = mock_resp
    with pytest.raises(Exception) as e_info:
        d = Downloader('test', download_dir=_tmp_dir.strpath, url='')
        assert e_info.value.message == "Couldn't fetch model data."
Пример #5
0
def test_get_filename_from_cd():
    cd = 'attachment; filename="model.tar.gz"; filename*=UTF-8' 'model.tar.gz'
    assert Downloader.get_filename_from_cd(cd) == 'model.tar.gz'