def test_ttl_vertex_date_property(self): """ gremlin接口创建图 + 顶点date属性的ttl功能 """ local_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) print(local_time) 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('personA').properties('name', 'age').primaryKeys('name')" \ ".ifNotExist().create();" \ "graph.schema().vertexLabel('personB').properties('name', 'date').primaryKeys('name')" \ ".ttl(5000L).ttlStartTime('date').ifNotExist().create();" \ "graph.schema().edgeLabel('linkA').sourceLabel('personA').targetLabel('personA')" \ ".properties('date').ifNotExist().create();" \ "graph.schema().edgeLabel('linkB').sourceLabel('personB').targetLabel('personB')" \ ".properties('age').ifNotExist().create();" \ "marko = graph.addVertex(T.label, 'personA', 'name', 'marko', 'age', 29);" \ "peter = graph.addVertex(T.label, 'personA', 'name', 'peter', 'age', 25);" \ "vadas = graph.addVertex(T.label, 'personB', 'name', 'vadas', 'date', '%s');" \ "josh = graph.addVertex(T.label, 'personB', 'name', 'josh', 'date', '%s');" % (local_time, local_time) # 插入设置ttl的数据 Gremlin().gremlin_post(query, auth=auth) # 进行查询 线程休眠时间大于ttl的设置时间 time.sleep(10) code, res = Gremlin().gremlin_post("g.V('2:vadas', '2:josh')") print(code, res) assert code == 200 assert res['result']['data'] == []
def test_ttl_vertex_common_property(self): """ gremlin接口创建图 + 顶点非date属性的ttl功能 """ # 插入设置ttl的数据 Gremlin().gremlin_post( "graph.schema().propertyKey('name').asText().ifNotExist().create();" "graph.schema().propertyKey('age').asInt().ifNotExist().create();" "graph.schema().propertyKey('date').asDate().ifNotExist().create();" "graph.schema().vertexLabel('personA').properties('name', 'age').primaryKeys('name')" ".ttl(5000L).ifNotExist().create();" "graph.schema().vertexLabel('personB').properties('name', 'date').primaryKeys('name')" ".ifNotExist().create();" "graph.schema().edgeLabel('linkA').sourceLabel('personA').targetLabel('personA')" ".properties('date').ifNotExist().create();" "graph.schema().edgeLabel('linkB').sourceLabel('personB').targetLabel('personB')" ".properties('age').ifNotExist().create();" "marko = graph.addVertex(T.label, 'personA', 'name', 'marko', 'age', 29);" "peter = graph.addVertex(T.label, 'personA', 'name', 'peter', 'age', 25);" "vadas = graph.addVertex(T.label, 'personB', 'name', 'vadas', 'date', '2020-02-02');" "josh = graph.addVertex(T.label, 'personB', 'name', 'josh', 'date', '2020-02-03');", auth=auth) # 进行查询 线程休眠时间大于ttl的设置时间 time.sleep(10) code, res = Gremlin().gremlin_post("g.V('1:marko', '1:prter')") print(code, res) assert code == 200 assert res['result']['data'] == []
def test_ttl_use_loader(self): """ ttl + loader导入 """ print(_cfg.server_backend) # 插入设置ttl的数据 顶点:艺人->ttl=5s;边:属于->ttl=5s gremlin = "graph.schema().propertyKey('名称').asText().ifNotExist().create();" \ "graph.schema().propertyKey('类型').asText().valueSet().ifNotExist().create();" \ "graph.schema().propertyKey('发行时间').asDate().ifNotExist().create();" \ "graph.schema().propertyKey('演员').asText().ifNotExist().create();" \ "graph.schema().vertexLabel('电影').useCustomizeStringId()" \ ".properties('名称','类型','发行时间').ifNotExist().create();" \ "graph.schema().vertexLabel('艺人').useCustomizeStringId().properties('演员')" \ ".ttl(5000L).ifNotExist().create();" \ "graph.schema().vertexLabel('类型').useCustomizeStringId().properties('类型').ifNotExist().create();" \ "graph.schema().vertexLabel('年份').useCustomizeStringId().properties('发行时间').ifNotExist().create();" \ "graph.schema().edgeLabel('导演').link('艺人','电影').ifNotExist().create();" \ "graph.schema().edgeLabel('演出').link('艺人','电影').ifNotExist().create();" \ "graph.schema().edgeLabel('属于').link('电影','类型').properties('发行时间')" \ ".ttl(5000L).ifNotExist().create();" \ "graph.schema().edgeLabel('发行于').link('电影','年份').properties('发行时间').ifNotExist().create();" code, res_gremlin = Gremlin().gremlin_post(gremlin, auth=auth) print(code, res_gremlin) assert 200 assert res_gremlin['result']['data'][0]['name'] == '发行于' cmd = "%s/bin/hugegraph-loader.sh -h %s -p %d -g %s -f %s " res = InsertData(cmd, struct='struct_movie.json', dir='movie').load_graph() res.communicate() # stdout, stderr = res.communicate() # print(' ---> ' + str(stdout) + ' === ' + str(stderr)) # 进行查询 线程休眠时间大于ttl的设置时间 time.sleep(30) # 断言 code, res = Gremlin().gremlin_post("g.V().count();", auth=auth) assert code == 200 assert res['result']['data'][ 0] != 16034 # rocksdb后端中的设置ttl,进行count()操作有bug code, res = Gremlin().gremlin_post("g.E().count();", auth=auth) assert code == 200 assert res['result']['data'][ 0] == 83809 # rocksdb后端中的设置ttl,进行count()操作有bug code, res = Gremlin().gremlin_post("g.V('吴宇森');", auth=auth) assert code == 200 assert res['result']['data'] == [] code, res = Gremlin().gremlin_post("g.E('S铁汉柔情 > 3 >> S动作');", auth=auth) assert code == 200 assert res['result']['data'] == []
def tools_assert(): """ 进行gremlin 查询 :return: """ if _cfg.is_auth: code_v, res_v = Gremlin().gremlin_post("g.V().count()", auth=_cfg.admin_password) code_e, res_e = Gremlin().gremlin_post("g.E().count()", auth=_cfg.admin_password) return res_v['result']["data"][0], res_e['result']["data"][0] else: code_v, res_v = Gremlin().gremlin_post("g.V().count()") code_e, res_e = Gremlin().gremlin_post("g.E().count()") return res_v['result']["data"][0], res_e['result']["data"][0]
def loader_assert(self): """ 进行gremlin 查询 :return: """ if self.is_auth: code_v, res_v = Gremlin().gremlin_post("g.V().count()", auth=self.auth) code_e, res_e = Gremlin().gremlin_post("g.E().count()", auth=self.auth) return res_v['result']["data"][0], res_e['result']["data"][0] else: code_v, res_v = Gremlin().gremlin_post("g.V().count()") code_e, res_e = Gremlin().gremlin_post("g.E().count()") return res_v['result']["data"][0], res_e['result']["data"][0]
def test_get_edge_by_page(): """ 根据条件获取边 :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('link').sourceLabel('person').targetLabel('person')" \ ".properties('date').ifNotExist().create();" \ "marko = graph.addVertex(T.label, 'person', 'name', 'marko', 'age', 18);" \ "vadas = graph.addVertex(T.label, 'person', 'name', 'vadas', 'age', 19);" \ "marko.addEdge('link', vadas, 'date', '2021-05-07');" \ "marko.addEdge('link', marko, 'date', '2021-06-08');" code, res = Gremlin().gremlin_post(query, auth=auth) print(code, res) assert code == 200 condition = {'vertex_id': '"1:marko"', 'limit': 1, 'page': ''} code, res = Edge().get_filter_edge(condition=condition, auth=auth) print(code, res) assert code == 200 assert len(res['edges']) == 1 assert res['page'] != ''
def setUp(self): """ 测试case开始 :resurn: """ Gremlin().gremlin_post('graph.truncateBackend();', auth=auth) # gremlin语句进行clear操作
def setUp(self): """ 测试case开始 :resurn: """ Gremlin().gremlin_post('graph.truncateBackend();', auth=auth) # gremlin语句进行clear操作 # 创建group body = { "group_name": "gremlin", "group_description": "group can execute gremlin" } code, res = Auth().post_groups(body, auth=auth) print(code, res) # 创建 target body = { "target_url": '%s:%d' % (_cfg.graph_host, _cfg.server_port), "target_name": "gremlin", "target_graph": _cfg.graph_name, "target_resources": [{ "type": "GREMLIN", "properties": None, "label": "*" }] } code, res = Auth().post_targets(body, auth=auth) print(code, res)
def test_create_search_vertex_indexlabel_int_error(): """ int类型的属性 & search索引 & 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": "searchByAgeByVertex", "base_type": "VERTEX_LABEL", "base_value": "person", "index_type": "SEARCH", "fields": ["age"] } code, res = Schema().create_index(body, auth=auth) print(code, res) assert code == 400 assert res[ 'message'] == "Search index can only build on text property, but got INT(age)"
def setUp(self): """ 每条case的前提条件 :return: """ init_graph() GraphConnection().add_graph_connect(body={ "name": _cfg.graph_name + "_test1", "graph": _cfg.graph_name, "host": _cfg.graph_host, "port": _cfg.server_port }) query = { "content": "graph.schema().propertyKey('名称').asText().ifNotExist().create();" "graph.schema().propertyKey('类型').asText().valueSet().ifNotExist().create();" "graph.schema().propertyKey('发行时间').asDate().ifNotExist().create();" "graph.schema().vertexLabel('电影').useCustomizeStringId().properties('名称', '类型', '发行时间')" ".nullableKeys('类型','发行时间').ifNotExist().create();" "graph.schema().vertexLabel('艺人').useCustomizeStringId().ifNotExist().create();" "graph.schema().vertexLabel('类型').useCustomizeStringId().ifNotExist().create();" "graph.schema().vertexLabel('年份').useCustomizeStringId().ifNotExist().create();" "graph.schema().edgeLabel('导演').link('艺人', '电影').ifNotExist().create();" "graph.schema().edgeLabel('演出').link('艺人', '电影').ifNotExist().create();" "graph.schema().edgeLabel('属于').link('电影', '类型').properties('发行时间').ifNotExist().create();" "graph.schema().edgeLabel('发行于').link('电影', '年份').ifNotExist().create();" } Gremlin().gremlin_post(query=query["content"], host=_cfg.graph_host, port=_cfg.server_port)
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_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_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 init_graph(): """ 对测试环境进行初始化操作 """ if _cfg.server_backend == 'cassandra': clear_graph() else: Gremlin().gremlin_post('graph.truncateBackend();', auth=auth) # 适用gremlin语句进行truncate操作
def init_graph(): """ 对测试环境进行初始化操作 """ if _cfg.server_backend == 'cassandra': clear_graph() else: Gremlin().gremlin_post('graph.truncateBackend();', auth=auth) # 适用gremlin语句进行truncate操作 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_name').properties('name').primaryKeys('name').ifNotExist().create();" \ "graph.schema().vertexLabel('person_age').properties('age').primaryKeys('age').ifNotExist().create();" \ "graph.schema().vertexLabel('person_date').properties('date').primaryKeys('date').ifNotExist().create();" code, res = Gremlin().gremlin_post(query, auth=auth) return code == 200
def test_gremlin_post(): """ 执行gremlin post请求的同步任务 进行清空操作 """ query = "g.V().limit(10);" code, res = Gremlin().gremlin_post(query, auth=auth) print(code, res) assert code == 200 assert res['result']['data'] == []
def setup(self): """ 测试case开始 :param self: :return: """ if _cfg.server_backend == 'cassandra': clear_graph() else: Gremlin().gremlin_post('graph.truncateBackend();') # 适用gremlin语句进行truncate操作
def test_gremlin_get(): """ 执行gremlin get请求的同步任务 """ init_graph() param = {"gremlin": "%s.traversal().V().count()" % _cfg.graph_name} code, res = Gremlin().gremlin_get(param=param, auth=auth) print(code, res) assert code == 200 assert res['result']['data'] == [0]
def setup_class(self): """ 测试类开始 """ if _cfg.server_backend == 'cassandra': clear_graph() else: Gremlin().gremlin_post('graph.truncateBackend();') # 适用gremlin语句进行truncate操作 InsertData(gremlin='gremlin_alg_03.txt').gremlin_graph()
def test_aggregate_date_original(self): """ 聚合属性 old """ # first load query1 = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \ "graph.schema().propertyKey('first_time').asDate().calcOld().ifNotExist().create();" \ "graph.schema().vertexLabel('person').properties('name', 'first_time')" \ ".primaryKeys('name').ifNotExist().create();" \ "graph.schema().edgeLabel('link').sourceLabel('person').targetLabel('person')" \ ".properties('name', 'first_time').ifNotExist().create();" \ "a = graph.addVertex(T.label, 'person', 'name', 'a', 'first_time', '2016-01-10 10:23:28');" \ "b = graph.addVertex(T.label, 'person', 'name', 'b', 'first_time', '2021-01-10 10:23:28');" \ "a.addEdge('link', b, 'name', 'link', 'first_time', '2021-11-10 10:23:28');" code, res = Gremlin().gremlin_post(query1, auth=auth) print(code, res) assert code == 200 # second load query2 = "a = graph.addVertex(T.label, 'person', 'name', 'a', 'first_time', '2018-01-10 10:23:28');" \ "b = graph.addVertex(T.label, 'person', 'name', 'b', 'first_time', '2019-01-10 10:23:28');" \ "a.addEdge('link', b, 'name', 'link', 'first_time', '2020-11-10 10:23:28');" code, res = Gremlin().gremlin_post(query2, auth=auth) print(code, res) assert code == 200 # assert vertex code, res = Gremlin().gremlin_post("g.V()", auth=auth) print(code, res) assert code == 200 v = res['result']['data'][0] if v['id'] == '1:b': assert v['properties']['first_time'] == '2021-01-10 10:23:28.000' else: assert v['properties']['first_time'] == '2016-01-10 10:23:28.000' # assert edge code, res = Gremlin().gremlin_post("g.E()", auth=auth) print(code, res) assert code == 200 assert res['result']['data'][0]['properties']['first_time'] == '2021-11-10 10:23:28.000'
def test_aggregate_int_min(self): """ 聚合属性 min """ # first load query1 = "graph.schema().propertyKey('name').asText().ifNotExist().create();" \ "graph.schema().propertyKey('min_num').asInt().calcMin().ifNotExist().create();" \ "graph.schema().vertexLabel('person').properties('name', 'min_num')" \ ".primaryKeys('name').ifNotExist().create();" \ "graph.schema().edgeLabel('link').sourceLabel('person').targetLabel('person')" \ ".properties('name', 'min_num').ifNotExist().create();" \ "a = graph.addVertex(T.label, 'person', 'name', 'a', 'min_num', 20160110);" \ "b = graph.addVertex(T.label, 'person', 'name', 'b', 'min_num', 20210110);" \ "a.addEdge('link', b, 'name', 'link', 'min_num', 20211110);" code, res = Gremlin().gremlin_post(query1, auth=auth) print(code, res) assert code == 200 # second load query2 = "a = graph.addVertex(T.label, 'person', 'name', 'a', 'min_num', 20180110);" \ "b = graph.addVertex(T.label, 'person', 'name', 'b', 'min_num', 20190110);" \ "a.addEdge('link', b, 'name', 'link', 'min_num', 20201110);" code, res = Gremlin().gremlin_post(query2, auth=auth) print(code, res) assert code == 200 # assert vertex code, res = Gremlin().gremlin_post("g.V()", auth=auth) print(code, res) assert code == 200 v = res['result']['data'][0] if v['id'] == '1:b': assert v['properties']['min_num'] == 20190110 else: assert v['properties']['min_num'] == 20161110 # assert edge code, res = Gremlin().gremlin_post("g.E()", auth=auth) print(code, res) assert code == 200 assert res['result']['data'][0]['properties']['min_num'] == 20201110
def init_graph(): """ 对测试环境进行初始化操作 """ if _cfg.server_backend == 'cassandra': clear_graph() else: Gremlin().gremlin_post('graph.truncateBackend();', auth=auth) # 适用gremlin语句进行truncate操作 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').primaryKeys('name').ifNotExist().create();" \ "graph.schema().edgeLabel('link').sourceLabel('person').targetLabel('person')" \ ".properties('name', 'age', 'date').ifNotExist().create();" \ "a = graph.addVertex(T.label, 'person', 'name', 'marko');" \ "b = graph.addVertex(T.label, 'person', 'name', 'vadas');" \ "a.addEdge('link', b, 'name', 'test', 'age', 29, 'date', '2021-02-07');" print(query) code, res = Gremlin().gremlin_post(query, auth=auth) return code == 200
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 gremlin_create_graph(file_name, auth=None): """ 读取文件 & 请求gremlin接口创建图 """ gremlin_str = '' n = 0 with open(file_name, 'r') as f: for line in f: each_line = line.strip('\n') if line.startswith('graph'): Gremlin().gremlin_post(each_line, auth=auth) elif line.startswith('#') or line is None: pass else: if n == 200: n = 0 gremlin_str += each_line Gremlin().gremlin_post(gremlin_str, auth=auth) gremlin_str = '' else: n += 1 gremlin_str += each_line Gremlin().gremlin_post(gremlin_str, auth=auth)
def test_pageRank_01(self): """ :return: """ body = {} code, res = Algorithm().post_page_rank(body, auth=auth) id = res["task_id"] if id > 0: result = get_task_res(id, 120, auth=auth) print(result) rank_code, rank_res = Gremlin().gremlin_post("g.V('1:marko')") print(rank_code, rank_res) assert result['last_changed_rank'] == 0.00015807441539228417 and \ rank_res['result']['data'][0]['properties']['r_rank'] == 0.05084635172453192 else: assert 0
def setUp(self): """ 测试case开始 :resurn: """ Gremlin().gremlin_post('graph.truncateBackend();', auth=auth) # gremlin语句进行clear操作 # 创建group body = { "group_name": "gremlin", "group_description": "group can execute gremlin" } code, res = Auth().post_groups(body, auth=auth) print(code, res) # 创建 user body = {"user_name": "tester", "user_password": "******"} code, res = Auth().post_users(body, auth=auth) print(code, res)
def test_get_task(): """ 获取执行成功的所有tasks :return: """ if init_graph(): code, res = Gremlin().gremlin_job("g.V().count()", auth=auth) print(code, res) if code == 201: param = {'status': 'SUCCESS'} time.sleep(30) t_code, t_res = Task().get_tasks(param=param, auth=auth) print(t_code, t_res) assert t_code == 200 assert t_res['tasks'][0]['task_name'] == 'g.V().count()' else: pass else: assert 0
def init_graph(): """ 对测试环境进行初始化操作 """ code, res = GraphConnection().get_graph_connect() assert code == 200 connection_list = res['data']['records'] for each in connection_list: each_id = each['id'] each_graph = each['graph'] each_host = each['host'] each_port = each['port'] # clear graph if _cfg.server_backend == 'cassandra': clear_graph(graph_name=each_graph, graph_host=each_host, graph_port=each_port) else: Gremlin().gremlin_post('graph.truncateBackend();') # 适用gremlin语句进行truncate操作 # delete graph_connection code, res = GraphConnection().delete_graph_connect(each_id) assert code == 200
def test_get_indexlabel_by_name(): """ 根据name查询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();" \ "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().get_index_by_name(index_name, auth=auth) print(code, res) assert code == 200 assert res['name'] == 'rangeByAgeByVertex'
def test_get_all_indexlabels(): """ 查询所有vertexlabels """ 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 code, res = Schema().get_index(auth=auth) print(code, res) assert code == 200 assert len(res['indexlabels']) == 1 assert res['indexlabels'][0]['name'] == 'rangeByAgeByVertex'