def test_create_range_edge_indexlabel(): """ int类型的属性 & range索引 & edgelabel """ init_graph() query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \ "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \ "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \ "graph.schema().vertexLabel('person').properties('name', 'age')" \ ".primaryKeys('name').ifNotExist().create();"\ "graph.schema().edgeLabel('knows').sourceLabel('person').targetLabel('person')" \ ".properties('date').ifNotExist().create()" code, res = Gremlin().gremlin_post(query, auth=auth) assert code == 200 body = { "name": "rangeByDateByEdge", "base_type": "EDGE_LABEL", "base_value": "knows", "index_type": "RANGE", "fields": ["date"] } code, res = Schema().create_index(body, auth=auth) print(code, res) assert code == 202 task_id = res['task_id'] result = get_task_res(task_id, 120, auth=auth) if result: assert 1
def test_eigenvector_centrality_19(self): """ param = [depth, sample, top, degree, source_sample, direction, label] :return: """ body = { "depth": 5, "degree": 50, "sample": -1, "top": 10, "source_sample": 10, "direction": "BOTH", "label": "created" } code, res = Algorithm().post_eigenvector_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == { '2:ripple': 3, '1:marko': 3, '1:peter': 3, '1:josh': 1, '1:vadas': 1, '2:lop': 1 } else: assert 0
def test_closeness_centrality_17(self): """ param=[depth, degree, sample, top, source_sample, direction] :return: """ body = { "depth": 5, "degree": 50, "sample": -1, "top": 10, "source_sample": -1, "direction": "OUT" } code, res = Algorithm().post_closeness_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == { '1:marko': 3.5, '1:peter': 2.0, '2:lop': 1.0, '2:ripple': 0.0, '1:josh': 0.0, '1:vadas': 0.0 } else: assert 0
def test_delete_indexlabel(): """ 删除索引 :return: """ init_graph() query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \ "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \ "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \ "graph.schema().vertexLabel('person').properties('name', 'age')" \ ".primaryKeys('name').ifNotExist().create();" \ "graph.schema().edgeLabel('knows').sourceLabel('person').targetLabel('person')" \ ".properties('date').ifNotExist().create();" \ "graph.schema().indexLabel('rangeByAgeByVertex').onV('person').by('age').range().ifNotExist().create();" code, res = Gremlin().gremlin_post(query, auth=auth) assert code == 200 index_name = 'rangeByAgeByVertex' code, res = Schema().delete_index(index_name, auth=auth) print(code, res) assert code == 202 task_id = res['task_id'] result = get_task_res(task_id, 120, auth=auth) if result: assert 1
def test_delete_edgeLabel_by_name(): """ 根据name查看edgeLabel """ init_graph() body = { "name": "link", "source_label": "person_name", "target_label": "person_name", "frequency": "SINGLE", "properties": ["name"], "sort_keys": [], "nullable_keys": ["name"], "enable_label_index": True, "user_data": { "super": "animal" } } code, res = Schema().create_edgeLabel(body, auth=auth) assert code == 201 assert res['status'] == 'CREATED' assert res['properties'] == ['name'] # eliminate property && userdata code, res = Schema().delete_edgeLabel("link", auth=auth) print(code, res) assert 202 res = get_task_res(res['task_id'], 60, auth=auth) print(res)
def test_stressCentrality_01(self): """ :return: """ body = {"depth": 10} code, res = Algorithm().post_stress_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == { '1:marko': 8, '1:josh': 8, '1:o': 8, '1:peter': 0, '2:p': 8, '1:r': 0, '1:s': 0, '1:wang': 0, '1:qian': 0, '2:ripple': 0, '1:li': 0, '1:vadas': 0, '2:zhao': 0, '2:lop': 8, '2:e': 0, '1:h': 8 } else: assert 0
def test_betweeness_centrality_16(self): """ params = [depth、sample、top、source_sample、degree、direction] :return: """ body = { "depth": 5, "degree": 50, "sample": -1, "top": 10, "source_sample": -1, "direction": "IN" } code, res = Algorithm().post_betweeness_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == { '1:vadas': 4.0, '1:peter': 4.0, '2:ripple': 2.0, '2:lop': 2.0, '1:marko': 0.0, '1:josh': 0.0 } else: assert 0
def test_create_secondary_vertex_indexlabel(): """ int类型的属性 & secondary索引 & vertexlabel """ init_graph() query = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \ "graph.schema().propertyKey('age').asInt().ifNotExist().create();" \ "graph.schema().propertyKey('date').asDate().ifNotExist().create();" \ "graph.schema().vertexLabel('person').properties('name', 'age')" \ ".primaryKeys('name').ifNotExist().create();"\ "graph.schema().edgeLabel('knows').sourceLabel('person').targetLabel('person')" \ ".properties('date').ifNotExist().create()" code, res = Gremlin().gremlin_post(query, auth=auth) assert code == 200 body = { "name": "secondaryByAgeByVertex", "base_type": "VERTEX_LABEL", "base_value": "person", "index_type": "SECONDARY", "fields": ["age"] } code, res = Schema().create_index(body, auth=auth) print(code, res) assert code == 202 task_id = res['task_id'] result = get_task_res(task_id, 120, auth=auth) if result: assert 1
def test_gremlin_job(): """ 执行gremlin异步任务 """ init_graph() query = "g.V().count();" code, res = Gremlin().gremlin_job(query, auth=auth) print(code, res) assert code == 201 assert res == {'task_id': 1} t_res = get_task_res(res['task_id'], 30, auth=auth) assert str(t_res) == '[0]'
def test_lpa_05(self): """ :return: """ body = {"direction": "IN", "workers": 0} code, res = Algorithm().post_lpa(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result else: assert 0
def test_lpa_01(self): """ :return: """ body = {} code, res = Algorithm().post_lpa(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result else: assert 0
def test_lpa_11(self): """ :return: """ body = {"source_label": "person", "workers": 0} code, res = Algorithm().post_lpa(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result else: assert 0
def test_kcore_04(self): """ :return: """ body = {"direction": "IN", "k": 2} code, res = Algorithm().post_kcore(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 300, auth=auth) print(result) assert result == {'kcores': []} else: assert 0
def test_rings_detect_03(self): """ :return: """ body = {"depth": 5, "limit": 3} code, res = Algorithm().post_rings_detect(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert len(result['rings']) == 3 else: assert 0
def test_triangle_count_04(self): """ param = [direction, degree] :return: """ body = {"direction": "OUT"} code, res = Algorithm().post_triangle_count(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == {'edges_out': 13, 'vertices_out': 7, 'triangles': 2} else: assert 0
def test_count_vertex(self): """ 统计顶点信息接口 :return: """ body = {} code, res = Algorithm().post_count_vertex(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == {'software': 5, 'person': 11, '*': 16} else: assert 0
def test_rings_detect_04(self): """ param = [depth, direction] :return: """ body = {"depth": 5, "direction": "IN"} code, res = Algorithm().post_rings_detect(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert len(result['rings']) == 0 else: assert 0
def test_rings_detect_02(self): """ param = [depth, source_label] :return: """ body = {"depth": 5, "source_label": "男人"} code, res = Algorithm().post_rings_detect(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert len(result['rings']) == 8 else: assert 0
def test_rings_detect_20(self): """ param = [depth, count_only, workers] :return: """ body = {"depth": 5, "count_only": True, "workers": 10} code, res = Algorithm().post_rings_detect(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result['rings_count'] == 18 else: assert 0
def test_rings_detect_08(self): """ param = [depth, capacity] :return: """ body = {"depth": 5, "capacity": 50} code, res = Algorithm().post_rings_detect(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert len(result['rings']) == 18 else: assert 0
def test_rings_detect_17(self): """ param = [depth, direction, degree, workers] :return: """ body = {"direction": "BOTH", "depth": 5, "degree": 50, "workers": 0} code, res = Algorithm().post_rings_detect(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert len(result['rings']) == 18 else: assert 0
def test_degree_centrality_08(self): """ param = [top] :return: """ body = {"top": 5} code, res = Algorithm().post_degree_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == {'2:ripple': 3, '1:marko': 3, '1:peter': 3, '1:josh': 1, '1:vadas': 1} else: assert 0
def test_count_edge(self): """ 统计边信息接口 :return: """ body = {} code, res = Algorithm().post_count_edge(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == {'created': 8, '*': 13, 'knows': 5} else: assert 0
def test_degree_centrality_12(self): """ param = [top、direction、label] :return: """ body = {"direction": "OUT", "top": 5, "label": "created"} code, res = Algorithm().post_degree_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == {'1:marko': 1, '1:peter': 1} else: assert 0
def test_degree_centrality_06(self): """ param = [direction] :return: """ body = {"direction": "IN"} code, res = Algorithm().post_degree_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == {'1:josh': 1, '1:peter': 1, '1:vadas': 1, '2:ripple': 3} else: assert 0
def test_degree_centrality_02(self): """ param = [label] :return: """ body = {"label": "created"} code, res = Algorithm().post_degree_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == {'1:marko': 1, '1:peter': 1, '2:ripple': 2} else: assert 0
def test_degree_centrality_03(self): """ param = [label] :return: """ body = {"label": "knows"} code, res = Algorithm().post_degree_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == {'1:josh': 1, '1:marko': 2, '1:peter': 2, '1:vadas': 1} else: assert 0
def test_betweeness_centrality_12(self): """ params = [depth、sample、top] :return: """ body = {"depth": 5, "sample": -1, "top": 3} code, res = Algorithm().post_betweeness_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == {'1:vadas': 9.0, '1:peter': 9.0, '2:ripple': 4.0} else: assert 0
def test_kcore_01(self): """ 无参数 :return: """ body = {} code, res = Algorithm().post_kcore(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 300, auth=auth) print(result) assert result == {'kcores': []} else: assert 0
def test_degree_centrality_05(self): """ param = [direction] :return: """ body = {"direction": "OUT"} code, res = Algorithm().post_degree_centrality(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) assert result == {'2:lop': 1, '1:marko': 3, '1:peter': 2} else: assert 0