Ejemplo n.º 1
0
def test_searcher_returns_dictionary(searcher: Searcher, mocker):
    """
    The searcher must return a json formatted SRA resultset
    """
    mocker.patch("Bio.Entrez.esearch")
    Entrez.esearch.return_value = io.StringIO("{}")
    result = searcher.search("Human", max_results=3)
    assert isinstance(result, dict)
Ejemplo n.º 2
0
def test_searcher_searches_sra(searcher: Searcher, mocker):
    """
    Tests if the searcher, when supplied with a valid search string,
    calls the correct Biopython's Entrez methods
    """

    # We need to supply a return value to the esearch function.
    # That return value must be a buffer.
    mocker.patch("Bio.Entrez.esearch")
    Entrez.esearch.return_value = io.StringIO("{}")

    searcher.search('"H**o sapiens"[Organism]')

    # pylint: disable=no-member
    Entrez.esearch.assert_called_with(
        "sra", '"H**o sapiens"[Organism]', retmax=10, retmode="json"
    )
Ejemplo n.º 3
0
def test_searcher_configurer_entrez():
    """
    In order for everything to work, the Searcher must set Entrez's e-mail and
    API Key parameters
    """

    Searcher(email="*****@*****.**", api_key="3141516")

    assert Entrez.email == "*****@*****.**"
    assert Entrez.api_key == "3141516"
Ejemplo n.º 4
0
def test_searcher_initialization(searcher):
    """
    Tests a searcher initialization parameters
    """

    assert isinstance(searcher, Searcher)
    assert searcher.db == "sra"

    new_searcher = Searcher("*****@*****.**", db="other_db")
    assert new_searcher.db == "other_db"
Ejemplo n.º 5
0
def test_searcher_format(searcher: Searcher):
    """
    The searcher must return data in an specified format
    """
    result = searcher.search("Human", max_results=3)

    assert isinstance(result, dict)
    assert "header" in result.keys()
    assert "esearchresult" in result.keys()
    jsonschema.validate(result, SEARCH_RESULT_SCHEMA)
Ejemplo n.º 6
0
def test_fetch_result(searcher: Searcher, mocker):
    """
    Given an Entrez UID, the searcher must acquire the related data
    """
    mocker.patch("Bio.Entrez.efetch")
    Entrez.efetch.return_value = open(
        Path(__file__).parent.absolute().joinpath("sample_efetch_result.xml")
    )

    data = searcher.fetch("8801091")

    # pylint: disable=no-member
    Entrez.efetch.assert_called()

    assert data
    assert isinstance(data, dict)
Ejemplo n.º 7
0
def searcher():
    """
    Fixture that provides a Searcher instance
    """
    return Searcher("*****@*****.**")