def test_not_property(client, submitter, pg_driver_clean, cgci_blgsp): post_example_entities_together(client, pg_driver_clean, submitter) with pg_driver_clean.session_scope() as s: s.merge( models.Case('case1', submitter_id='s1', project_id='CGCI-BLGSP')) s.merge( models.Case('case2', submitter_id='s2', project_id='CGCI-BLGSP')) r = client.post(path, headers=submitter, data=json.dumps({ 'query': """{ case (not: {submitter_id: "s1"}, submitter_id: ["s1", "s2"]) { id submitter_id } }""", })) assert r.json == { "data": { 'case': [ { "id": "case2", "submitter_id": "s2" }, ], } }, r.data
def test_with_path_to_any(client, submitter, pg_driver_clean, cgci_blgsp): post_example_entities_together(client, pg_driver_clean, submitter) with pg_driver_clean.session_scope() as s: props = dict(project_id='CGCI-BLGSP', state='validated') case1 = models.Case('case1', submitter_id='case1', **props) case2 = models.Case('case2', submitter_id='case2', **props) sample1 = models.Sample('sample1', submitter_id='sample1', **props) sample2 = models.Sample('sample2', submitter_id='sample2', **props) case1.samples = [sample1] case2.samples = [sample2] s.add_all((case1, case2)) r = client.post(path, headers=submitter, data=json.dumps({ 'query': """query Test($sampleId1: String, $sampleId2: String) { a: _case_count (with_path_to_any: [ {type: "sample", submitter_id: $sampleId1} {type: "sample", submitter_id: $sampleId2} ]) b: _case_count (with_path_to_any: [ {type: "sample", submitter_id: $sampleId1} ]) c: _case_count (with_path_to_any: [ {type: "sample", submitter_id: $sampleId2} ]) d: _case_count (with_path_to: [ {type: "sample", submitter_id: $sampleId1} ]) e: _case_count (with_path_to: [ {type: "sample", submitter_id: $sampleId2} ]) f: _case_count (with_path_to: [ {type: "sample", submitter_id: $sampleId1} {type: "sample", submitter_id: $sampleId2} ]) }""", 'variables': { "sampleId1": sample1.submitter_id, "sampleId2": sample2.submitter_id, } })) assert r.status_code == 200, r.data assert r.json == { 'data': { 'a': 2, 'b': 1, 'c': 1, 'd': 1, 'e': 1, 'f': 0, } }, r.data
def test_auth_node_subclass(client, submitter, pg_driver_clean, cgci_blgsp): with pg_driver_clean.session_scope(): blgsp = pg_driver_clean.nodes(models.Project).props(code='BLGSP').one() blgsp.cases += [models.Case('id1', project_id='CGCI-BLGSP')] blgsp.cases += [models.Case('id2', project_id='OTHER-OTHER')] r = client.post(path, headers=submitter, data=json.dumps( {'query': """query Test { case { project_id }}"""})) with pg_driver_clean.session_scope(): assert len(r.json['data']['case']) == 1
def test_export_all_node_types(client, pg_driver, cgci_blgsp, submitter): post_example_entities_together(client, submitter) with pg_driver.session_scope() as s: case = pg_driver.nodes(md.Case).first() new_case = md.Case(str(uuid.uuid4())) new_case.props = case.props new_case.submitter_id = 'case-2' s.add(new_case) case_count = pg_driver.nodes(md.Case).count()
def test_export_all_node_types_json(client, pg_driver, cgci_blgsp, require_index_exists_off, submitter): post_example_entities_together(client, submitter, extended_data_fnames) with pg_driver.session_scope() as s: case = pg_driver.nodes(md.Case).first() new_case = md.Case(str(uuid.uuid4())) new_case.props = case.props new_case.submitter_id = "case-2" s.add(new_case) case_count = pg_driver.nodes(md.Case).count()
def test_property_lists(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() as s: s.merge( models.Case('case1', submitter_id='s1', project_id='CGCI-BLGSP')) s.merge( models.Case('case2', submitter_id='s2', project_id='CGCI-BLGSP')) data = json.dumps({ 'query': """{ case (submitter_id: ["s1", "s2"]) { id submitter_id }, c1: _transaction_log_count(project_id: ["CGCI-BLGSP"]) c2: _transaction_log_count(project_id: ["CGCI-FAKE"]) c3: _transaction_log_count(project_id: "CGCI-BLGSP") }""", }) response = client.post(path, headers=submitter, data=data) # fix for the unicode artifacts expected_json = json.loads( json.dumps({ "data": { 'case': [ { "id": "case1", "submitter_id": "s1" }, { "id": "case2", "submitter_id": "s2" }, ], 'c1': 1, 'c2': 0, 'c3': 1, } })) assert response.json == expected_json, response.data
def test_without_path(client, submitter, pg_driver_clean, cgci_blgsp): post_example_entities_together(client, pg_driver_clean, submitter) with pg_driver_clean.session_scope(): blgsp = pg_driver_clean.nodes(models.Project).props(code='BLGSP').one() blgsp.cases += [models.Case('id1', project_id='CGCI-BLGSP')] data = json.dumps({ 'query': """ query Test { with : _case_count(with_path_to : {type: "aliquot"}) without: _case_count(without_path_to: {type: "aliquot"}) total : _case_count } """ }) r = client.post(path, headers=submitter, data=data) print r.data data = r.json['data'] assert data['with'] assert data['without'] assert data['with'] + data['without'] == data['total']