def test_metrics(mock_app, database, test_client, demo_data_path, match_objs):
    """Testing viewing the list of patients on server for authorized users"""

    # load demo data of 50 test patients
    inserted_ids = load_demo(demo_data_path, database)
    assert len(inserted_ids) == 50  # 50 test cases should be loaded

    # load mock matches into database
    database.matches.insert_many(match_objs)
    results = database.matches.find()
    assert len(list(results)) == 3

    # send a get request without being authorized
    response = mock_app.test_client().get("metrics")
    assert response.status_code == 200

    data = json.loads(response.data)
    assert data["disclaimer"]  # disclaimer should be returned
    metrics = data["metrics"]

    assert metrics["numberOfCases"] == 50
    assert metrics["numberOfSubmitters"] > 0
    assert metrics["numberOfGenes"] > metrics["numberOfUniqueGenes"]
    assert metrics["numberOfVariants"] > metrics["numberOfUniqueVariants"]
    assert metrics["numberOfFeatures"] > metrics["numberOfUniqueFeatures"]
    assert metrics["numberOfCasesWithDiagnosis"] > 0
    assert metrics[
        "numberOfUniqueGenesMatched"] == 0  # no gene was provided in match_obj results
    assert metrics["numberOfRequestsReceived"] == 2  # Sent 2 requests
    assert metrics[
        "numberOfPotentialMatchesSent"] == 1  # Just one has returned results
Ejemplo n.º 2
0
def demodata(ensembl_genes):
    """Adds a set of 50 demo patients to database"""
    click.echo('Adding 50 test patients to database..')
    click.echo('ENSEMBL GENES IS {}'.format(ensembl_genes))
    inserted_ids = load_demo(path_to_json_data=path_to_benchmark_patients, mongo_db=current_app.db,
        convert_to_ensembl=ensembl_genes)
    click.echo('inserted {} patients into db'.format(len(inserted_ids)))
Ejemplo n.º 3
0
def test_load_demo_patients(demo_data_path, database):
    """Testing if loading of 50 test patients in database is working as it should"""

    # demo data file should be present in the expected directory
    assert os.path.isfile(demo_data_path)

    # load demo data to mock database using function located under utils/load
    inserted_ids = load_demo(demo_data_path, database)
    assert len(inserted_ids) == 50 # 50 test cases should be loaded

    # make sure that trying to re-insert the same patients will not work
    re_inserted_ids = load_demo(demo_data_path, database)
    assert len(re_inserted_ids) == 0

    # try to call load_demo with an invalid patient file:
    inserted_ids = load_demo('this_is_a_fakey_json_file.json', database)
    assert len(inserted_ids) == 0
def test_patients(demo_data_path, database):
    """Tests the function that retrieves patient objects"""

    # load demo data in mock database
    inserted_ids = load_demo(demo_data_path, database)
    assert type(inserted_ids) == list
    assert len(inserted_ids) == 50  # 50 test cases are loaded

    # get all 50 patients available in database
    all_patients = list(patients(database=database))
    assert len(all_patients) == 50

    # test collecting just a few patients:
    selected_patients = list(patients(database=database, ids=inserted_ids[:3]))
    assert len(inserted_ids[:3]) == 3
    assert len(selected_patients) == 3
Ejemplo n.º 5
0
def test_metrics(mock_app, database, test_client, demo_data_path, match_objs):
    """Testing viewing the list of patients on server for authorized users"""

    # send a get request without being authorized
    response = mock_app.test_client().get('metrics')
    assert response.status_code == 401

    # add an authorized client to database
    ok_token = test_client['auth_token']

    add_node(mongo_db=mock_app.db, obj=test_client, is_client=True)

    # make sure that database contains at least one client with auth_token == test_client['auth_token']
    clients = mock_app.db['clients'].find({'auth_token': ok_token}).count()
    assert clients > 0

    # load demo data of 50 test patients
    inserted_ids = load_demo(demo_data_path, database)
    assert len(inserted_ids) == 50  # 50 test cases should be loaded

    # load mock matches into database
    database.matches.insert_many(match_objs)
    assert database.matches.find().count() == 3

    # if a valid token is provided the server should return metrics with patient data and matching results
    auth_response = mock_app.test_client().get('metrics',
                                               headers=auth_headers(ok_token))
    assert auth_response.status_code == 200

    data = json.loads(auth_response.data)
    assert data['disclaimer']  # disclaimer should be returned
    metrics = data['metrics']

    assert metrics['numberOfCases'] == 50
    assert metrics['numberOfSubmitters'] > 0
    assert metrics['numberOfGenes'] > metrics['numberOfUniqueGenes']
    assert metrics['numberOfVariants'] > metrics['numberOfUniqueVariants']
    assert metrics['numberOfFeatures'] > metrics['numberOfUniqueFeatures']
    assert metrics['numberOfCasesWithDiagnosis'] > 0
    assert metrics[
        'numberOfUniqueGenesMatched'] == 0  # no gene was provided in match_obj results
    assert metrics['numberOfRequestsReceived'] == 2  # Sent 2 requests
    assert metrics[
        'numberOfPotentialMatchesSent'] == 1  # Just one has returned results