def test_forge_http_stream(capsys): f = Forge(index="mdf") # Simple case res1 = f.http_stream(example_result1) assert isinstance(res1, types.GeneratorType) assert next( res1 ) == "This is a test document for Forge testing. Please do not remove.\n" # With multiple files res2 = f.http_stream((example_result2, {"info": {}})) assert isinstance(res2, types.GeneratorType) assert next( res2 ) == "This is a test document for Forge testing. Please do not remove.\n" assert next( res2 ) == "This is a second test document for Forge testing. Please do not remove.\n" assert next( res2 ) == "This is a test document for Forge testing. Please do not remove.\n" assert next( res2 ) == "This is a second test document for Forge testing. Please do not remove.\n" res3 = f.http_stream((example_result3, {"info": {}})) assert isinstance(res3, types.GeneratorType) assert next( res3 ) == "This is a test document for Forge testing. Please do not remove.\n" assert next( res3 ) == "This is a second test document for Forge testing. Please do not remove.\n" assert next( res3 ) == "This is a test document for Forge testing. Please do not remove.\n" assert next( res3 ) == "This is a second test document for Forge testing. Please do not remove.\n" # Too many results res4 = f.http_stream(list(range(10001))) assert next(res4)["success"] is False out, err = capsys.readouterr() assert "Too many results supplied. Use globus_download()" in out with pytest.raises(StopIteration): next(res4) # "Missing" files assert next(f.http_stream(example_result_missing)) is None out, err = capsys.readouterr() assert not os.path.exists("./should_not_exist.txt") assert ( "Error 404 when attempting to access " "'https://data.materialsdatafacility.org/test/should_not_exist.txt'" ) in out
def test_forge_anonymous(capsys): f = Forge(anonymous=True) # Test search assert len( f.search("mdf.source_name:ab_initio_solute_database", advanced=True, limit=300)) == 300 # Test aggregation assert len(f.aggregate("mdf.source_name:nist_xps_db")) > 10000 # Error on auth-only functions # http_download assert f.http_download({})["success"] is False out, err = capsys.readouterr() assert "Error: Anonymous HTTP download not yet supported." in out # globus_download assert f.globus_download({})["success"] is False out, err = capsys.readouterr() assert "Error: Anonymous Globus Transfer not supported." in out # http_stream res = f.http_stream({}) assert next(res)["success"] is False out, err = capsys.readouterr() assert "Error: Anonymous HTTP download not yet supported." in out with pytest.raises(StopIteration): next(res)