Ejemplo n.º 1
0
def test_answer_get_registered_queries():
    db = _get_test_db()
    qm = QueryManager(db=db, model_managers=[test_mm])
    # Put all types of queries in db, answer together
    qm.db.put_queries(test_email, 1, query_object, ['test'], subscribe=True)
    qm.db.put_queries(test_email, 1, dyn_query, ['test'], subscribe=True)
    qm.db.put_queries(test_email, 1, open_query, ['test'], subscribe=True)
    qm.db.put_queries(test_email, 1, interv_query, ['test'], subscribe=True)
    qm.answer_registered_queries('test')
    # Retrieve results for path query
    results = qm.get_registered_queries(test_email, 'path_property')
    qh = query_object.get_hash_with_model('test')
    assert qh in results
    assert len(results) == 1
    assert results[qh]['model'] == 'test'
    assert results[qh]['query'] == simple_query
    assert isinstance(results[qh]['date'], str)
    assert results[qh]['pysb'] == ['Pass', [test_response['3801854542']]], \
        (results[qh]['pysb'], test_response['3801854542'])
    assert results[qh]['pybel'] == ['Pass', [test_response['3801854542']]]
    assert results[qh]['signed_graph'][0] == 'Pass'
    assert results[qh]['unsigned_graph'][0] == 'Pass'
    # Retrieve results for dynamic query
    results = qm.get_registered_queries(test_email, 'dynamic_property')
    qh = dyn_query.get_hash_with_model('test')
    assert qh in results
    assert results[qh]['model'] == 'test'
    assert results[qh]['query'] == 'Active MAP2K1 is eventually high.'
    assert isinstance(results[qh]['date'], str)
    assert results[qh]['result'] == [
        'Pass', 'Satisfaction rate is 100% after 2 simulations.'
    ]
    assert isinstance(results[qh]['image'], str)
    # Retrieve results for open query
    results = qm.get_registered_queries(test_email, 'open_search_query')
    qh = open_query.get_hash_with_model('test')
    assert qh in results
    assert results[qh]['model'] == 'test'
    assert results[qh]['query'] == 'What does BRAF activate?'
    assert isinstance(results[qh]['date'], str)
    for mc_type in ['pysb', 'pybel', 'signed_graph', 'unsigned_graph']:
        assert results[qh][mc_type][0] == 'Pass'
        assert isinstance(results[qh][mc_type][1], list)
        assert test_response['3801854542']['path'] in [
            res['path'] for res in results[qh][mc_type][1]
        ]
    # Retrieve results for intervention query
    results = qm.get_registered_queries(test_email,
                                        'simple_intervention_property')
    qh = interv_query.get_hash_with_model('test')
    assert qh in results, results
    assert results[qh]['model'] == 'test'
    assert results[qh]['query'] == 'BRAF increases active MAP2K1.'
    assert isinstance(results[qh]['date'], str)
    assert results[qh]['result'] == [
        'Pass', 'Yes, the amount of target entity increased.'
    ]
    assert isinstance(results[qh]['image'], str)
Ejemplo n.º 2
0
def test_answer_get_registered_queries():
    db = _get_test_db()
    qm = QueryManager(db=db, model_managers=[test_mm])
    qm.db.put_queries('*****@*****.**',
                      1,
                      query_object, ['test'],
                      subscribe=True)
    qm.answer_registered_queries('test')
    results = qm.get_registered_queries('*****@*****.**')
    assert len(results) == 1
    assert results[0]['model'] == 'test'
    assert results[0]['query'] == simple_query
    assert isinstance(results[0]['response'], str)
    assert 'BRAF activates MAP2K1.' in results[0]['response'], \
        results[0]['response']
    assert isinstance(results[0]['date'], str)