def test_loqusdb_api_cases(loqus_api_app, monkeypatch):
    """Test fetching info on number of cases from loqusdb API"""
    nr_snvs = 15
    nr_svs = 12

    # GIVEN a mocked loqus API
    def mockapi(*args):
        return {
            "content": {
                "nr_cases_snvs": nr_snvs,
                "nr_cases_svs": nr_svs
            },
            "status_code": 200,
        }

    monkeypatch.setattr(loqus_extension, "api_get", mockapi)

    with loqus_api_app.app_context():
        # WHEN fetching the nr_cases with SNV variants
        n_cases = loqusdb.case_count("snv", "default")
        # THEN the API should parse the returned info correctly
        assert n_cases == nr_snvs

        # WHEN fetching the nr_cases with SV variants
        n_cases = loqusdb.case_count("sv", "default")
        # THEN the API should parse the returned info correctly
        assert n_cases == nr_svs
def test_loqus_api_cases_no_instance(loqus_api_app):
    """Test fetching info on number of cases from loqusdb API when the instance is not available"""

    with loqus_api_app.app_context():
        # WHEN fetching the nr_cases with SNV variants from an instance not available
        n_cases = loqusdb.case_count("snv", "default")

        # THEN the API shoud return 0 cases
        assert n_cases == 0
def test_loqusdb_api_cases_not_found(loqus_api_app, monkeypatch):
    """Test fetching info on number of cases from loqusdb API when the API is not funct"""
    def mockapi(*args):
        return {"message": {"details": "not found"}}

    monkeypatch.setattr(loqus_extension, "api_get", mockapi)

    with loqus_api_app.app_context():
        # WHEN fetching the nr_cases with SNV variants
        n_cases = loqusdb.case_count("snv", "default")
        # THEN the if no cases are found, it should return 0 cases
        assert n_cases == 0
Esempio n. 4
0
def test_loqusdb_exe_case_count_CalledProcessError(loqus_exe_app, monkeypatch):
    """Test the case count function in loqus extension that raises an exception"""

    # GIVEN replacing subprocess.check_output to raise CalledProcessError
    def mockcommand(*args):
        raise subprocess.CalledProcessError(123, "case_count")

    monkeypatch.setattr(loqus_extension, "execute_command", mockcommand)

    with loqus_exe_app.app_context():
        # THEN assert exception is caught and the value 0 is returned
        assert 0 == loqusdb.case_count(variant_category="snv")
Esempio n. 5
0
def test_loqusdb_exe_cases_ValueError(loqus_exe_app, monkeypatch):
    """Test the case count function in loqus extension"""

    # GIVEN a return value from loqusdb which is not an int
    def mockcommand(*args):
        return "nonsense"

    monkeypatch.setattr(loqus_extension, "execute_command", mockcommand)

    with loqus_exe_app.app_context():
        # THEN assert a value error is raised, but passed, and 0 is returned
        assert loqusdb.case_count(variant_category="snv") == 0
Esempio n. 6
0
def test_loqusdb_exe_cases(loqus_exe_app, monkeypatch):
    """Test the case count function in loqus executable extension"""

    nr_cases = 15

    # GIVEN a return value from loqusdb using a mocker
    def mockcommand(*args):
        return_value = b"%d" % nr_cases
        return return_value

    monkeypatch.setattr(loqus_extension, "execute_command", mockcommand)

    with loqus_exe_app.app_context():
        # WHEN fetching the number of cases
        res = loqusdb.case_count(variant_category="snv")
        # THEN assert the output is parsed correct
        assert res == nr_cases