Ejemplo n.º 1
0
def test_transaction_log_related_cases_filter(
        client, submitter, pg_driver_clean, cgci_blgsp):
    utils.reset_transactions(pg_driver_clean)
    post_example_entities_together(client, pg_driver_clean, submitter)
    data = json.dumps({
        'query': """
            {a: transaction_log (first: 1) { related_cases { id }}}
        """
    })
    r = client.post(path, headers=submitter, data=data)
    assert r.status_code == 200
    print r.data
    case_id = r.json['data']['a'][0]['related_cases'][0]['id']
    data = json.dumps({
        'query': """
            query Test($caseId: String) {
                a: transaction_log (related_cases: [$caseId]) {
                    related_cases { id submitter_id }
                }
            }
        """,
        "variables": {"caseId": case_id},
    })
    r = client.post(path, headers=submitter, data=data)
    assert r.status_code == 200
    print r.data
    related_case_doc = r.json['data']['a'][0]['related_cases'][0]
    assert related_case_doc['id'] == case_id
    assert related_case_doc['submitter_id']
Ejemplo n.º 2
0
def test_get_projects_anonymous(client, submitter, pg_driver_clean, cgci_blgsp,
                                public_dataset_api):

    post_example_entities_together(client, pg_driver_clean, submitter)
    with pg_driver_clean.session_scope() as s:
        project = models.Project("other",
                                 name="name",
                                 code="OTHER",
                                 dbgap_accession_number="phsid")
        program = pg_driver_clean.nodes(
            models.Program).props(name="CGCI").first()
        project.programs = [program]
        s.add(project)
    r = client.get("/datasets/projects")
    assert r.json == {
        "projects": [{
            "dbgap_accession_number": "phs000527",
            "code": "BLGSP",
            "name": "Burkitt Lymphoma Genome Sequencing Project"
        }, {
            "dbgap_accession_number": "phsid",
            "code": "OTHER",
            "name": "name"
        }]
    }
Ejemplo n.º 3
0
def test_authorized_call_with_protected_config(client, submitter,
                                               pg_driver_clean, cgci_blgsp):
    post_example_entities_together(client, pg_driver_clean, submitter)
    #: number of nodes to change project_id on, there should be 5
    with pg_driver_clean.session_scope() as s:
        cases = pg_driver_clean.nodes(models.Case).all()
        case_count = len(cases)
        for case in cases[0:-3]:
            case.project_id = "OTHER-OTHER"
            s.merge(case)
Ejemplo n.º 4
0
def test_transaction_log_documents(client, submitter, pg_driver_clean, cgci_blgsp):

    utils.reset_transactions(pg_driver_clean)
    post_example_entities_together(client, pg_driver_clean, submitter)
    r = client.post(path, headers=submitter, data=json.dumps({
        'query': """{ log: transaction_log {
        doc: documents { doc_size name }}}"""}))
    doc = r.json['data']['log'][0]['doc'][0]
    assert doc['name'] is None
    assert isinstance(doc['doc_size'], int)
Ejemplo n.º 5
0
def test_transaction_log_type(client, submitter, pg_driver_clean, cgci_blgsp):
    utils.reset_transactions(pg_driver_clean)
    post_example_entities_together(client, pg_driver_clean, submitter)
    r = client.post(path, headers=submitter, data=json.dumps({
        'query': """{ a: transaction_log { role type }}"""}))
    print r.data
    type_ = graphql.transaction.TransactionLog.TYPE_MAP['create']
    assert r.json['data']['a'][0]['type'] == type_
    r = client.post(path, headers=submitter, data=json.dumps({
        'query': """{
        a: transaction_log(type: "%s") { role type }
        }""" % type_}))
    print r.data
    assert r.json['data']['a']
Ejemplo n.º 6
0
def test_anonymous_call_with_public_config(client, submitter, pg_driver_clean,
                                           cgci_blgsp, public_dataset_api):
    post_example_entities_together(client, pg_driver_clean, submitter)
    with pg_driver_clean.session_scope() as s:
        project = models.Project("other", code="OTHER")
        program = pg_driver_clean.nodes(
            models.Program).props(name="CGCI").first()
        project.programs = [program]
        s.add(project)
        aliquot_count = pg_driver_clean.nodes(models.Aliquot).count()
        cases = pg_driver_clean.nodes(models.Case).all()
        case_count = len(cases)
        for case in cases[0:-3]:
            case.project_id = "CGCI-OTHER"
            s.merge(case)
Ejemplo n.º 7
0
def test_unauthorized_call_with_protected_config(client, submitter,
                                                 pg_driver_clean, cgci_blgsp,
                                                 mock_arborist_requests):
    post_example_entities_together(client, pg_driver_clean, submitter)

    mock_arborist_requests(auth_mapping={})

    r = client.get("/datasets?nodes=case,aliquot", headers=submitter)
    assert r.status_code == 200
    assert r.json == {}

    r = client.get("/datasets/projects", headers=submitter)

    assert r.status_code == 200
    assert r.json == {"projects": []}
Ejemplo n.º 8
0
def test_transaction_logs_order_desc(client, submitter, pg_driver_clean, cgci_blgsp):
    utils.reset_transactions(pg_driver_clean)
    post_example_entities_together(client, pg_driver_clean, submitter)
    with pg_driver_clean.session_scope():
        assert pg_driver_clean.nodes(models.submission.TransactionLog).count() == 1
    r = client.post(path, headers=submitter, data=json.dumps({
        'query': """{
          a: transaction_log (order_by_desc: "id") {
            id
            project_id
            created_datetime
          }
        }"""}))
    print r.data
    _original = r.json['data']['a']
    _sorted = sorted(_original, cmp=(lambda a, b: cmp(b['id'], a['id'])))
    assert _original == _sorted, r.data
Ejemplo n.º 9
0
def test_transaction_logs_quick_search(
        client, submitter, pg_driver_clean, cgci_blgsp):
    utils.reset_transactions(pg_driver_clean)
    post_example_entities_together(client, pg_driver_clean, submitter)
    with pg_driver_clean.session_scope():
        id_ = str(pg_driver_clean.nodes(models.submission.TransactionLog).first().id)
    r = client.post(path, headers=submitter, data=json.dumps({
        'query': """{
          a: transaction_log (quick_search: "%s") { id }
          b: transaction_log (quick_search: %s)   { id }
          c: transaction_log (quick_search: "A") { id }
        }""" % (id_, id_)}))
    assert r.json == {
        'data': {
            'a': [{'id': id_}],
            'b': [{'id': id_}],
            'c': [],
        }
    }, r.data
Ejemplo n.º 10
0
def test_transaction_log_entities(client, submitter, pg_driver_clean, cgci_blgsp):
    utils.reset_transactions(pg_driver_clean)
    post_example_entities_together(client, pg_driver_clean, submitter)

    # using response
    r = client.post(path, headers=submitter, data=json.dumps({
        'query': """{ log: transaction_log {
        doc: documents { resp: response { ent: entities { type }}}}}"""}))
    assert r.status_code == 200
    entities = r.json['data']['log'][0]['doc'][0]['resp']['ent']
    assert all(e['type'] for e in entities)

    # using response_json
    r = client.post(path, headers=submitter, data=json.dumps({
        'query': """{ log: transaction_log {
        doc: documents { resp: response_json }}}"""}))
    assert r.status_code == 200
    resp = json.loads(r.json['data']['log'][0]['doc'][0]['resp'])
    assert all(entity['type'] for entity in resp['entities'])
Ejemplo n.º 11
0
def test_transaction_log_related_cases(
        client, submitter, pg_driver_clean, cgci_blgsp):
    utils.reset_transactions(pg_driver_clean)
    post_example_entities_together(client, pg_driver_clean, submitter)

    r = client.post(path, headers=submitter, data=json.dumps({
        'query': """
        query Test {
          a: transaction_log (first: 1) {
            type documents {response { entities {related_cases {
              id submitter_id
            }}}}}
        }"""}))
    assert r.status_code == 200
    print(r.data)
    related_case = (r.json['data']
                    ['a'][0]
                    ['documents'][0]
                    ['response']
                    ['entities'][1]
                    ['related_cases'][0])
    assert 'submitter_id' in related_case
    assert 'id' in related_case
Ejemplo n.º 12
0
def test_transaction_log_entities_errors(
        client, submitter, pg_driver_clean, cgci_blgsp):
    utils.reset_transactions(pg_driver_clean)
    post_example_entities_together(client, pg_driver_clean, submitter)
    put_response = utils.put_entity_from_file(
        client, 'read_group_invalid.json', submitter=submitter, validate=False
    )
    transaction_id = put_response.json.get('transaction_id')

    # using response
    query = """
    {{ log: transaction_log( id: {} ) {{
        doc: documents {{ resp: response {{ ent: entities {{
        err: errors {{ type keys message }} }} }} }} }} }}
    """
    query = query.format(transaction_id)
    r = client.post(path, headers=submitter, data=json.dumps({
        'query': query
    }))
    assert r.status_code == 200
    error = r.json['data']['log'][0]['doc'][0]['resp']['ent'][0]['err'][0]

    # using response_json
    query = """
    {{ log: transaction_log( id: {} ) {{
        doc: documents {{ resp: response_json
    }} }} }}
    """
    query = query.format(transaction_id)
    r = client.post(path, headers=submitter, data=json.dumps({
        'query': query
    }))
    assert r.status_code == 200
    resp = json.loads(r.json['data']['log'][0]['doc'][0]['resp'])
    error = resp['entities'][0]['errors'][0]
    assert all(key in error for key in ('type', 'keys', 'message'))
Ejemplo n.º 13
0
def test_transaction_logs(client, submitter, pg_driver_clean, cgci_blgsp):
    utils.reset_transactions(pg_driver_clean)
    post_example_entities_together(client, pg_driver_clean, submitter)
    with pg_driver_clean.session_scope():
        assert pg_driver_clean.nodes(models.submission.TransactionLog).count() == 1