def test_reqiured_params(self): """ :return: """ json = { "sources": { "ids": [], "label": "男人" }, "min_neighbors": 2, "alpha": 0.60, "capacity": -1, "limit": -1, "with_intermediary": False, "with_vertex": True } code, res = Traverser().post_fusiform_similarity(json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual( res['similars'], {'1:贾代善': [{ 'id': '2:贾母', 'score': 0.6, 'intermediaries': [] }]})
def test_reqiured_params(self): """ source、max_depth :return: """ json = { "vertices": { "ids": ["1:vadas", "1:peter", "2:ripple"] }, "step": { "direction": "BOTH", "properties": {} }, "max_depth": 10, "capacity": 100000000, "with_vertex": True } code, res = Traverser().post_multi_node_shortestPath(json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(res['paths'], [{ 'objects': ['2:ripple', '1:josh', '1:marko', '1:vadas'] }, { 'objects': ['2:ripple', '1:josh', '2:lop', '1:peter'] }, { 'objects': ['1:vadas', '1:marko', '2:lop', '1:peter'] }])
def test_reqiured_params(self): """ source、max_depth :return: """ param_json = {'source': '"1:贾宝玉"', 'max_depth': 2} code, res = Traverser().get_rays(param_json, auth=auth) print(code, res) for i in res['rays']: print(i) self.assertEqual(code, 200) self.assertEqual(res['rays'], [{ 'objects': ['1:贾宝玉', '2:王夫人', '2:薛姨妈'] }, { 'objects': ['1:贾宝玉', '2:王夫人', '2:贾元春'] }, { 'objects': ['1:贾宝玉', '2:林黛玉', '2:贾敏'] }, { 'objects': ['1:贾宝玉', '2:史湘云', '1:史氏'] }, { 'objects': ['1:贾宝玉', '2:林黛玉', '1:林如海'] }, { 'objects': ['1:贾宝玉', '2:王夫人', '1:贾珠'] }, { 'objects': ['1:贾宝玉', '2:史湘云', '1:卫若兰'] }, { 'objects': ['1:贾宝玉', '2:王夫人', '1:贾政'] }, { 'objects': ['1:贾宝玉', '2:薛宝钗', '2:薛姨妈'] }])
def test_reqiured_params(self): """ source、max_depth :return: """ json = { "sources": { "ids": [], "label": "person", "properties": { "name": "vadas" } }, "targets": { "ids": [], "label": "software", "properties": { "name": "ripple" } }, "steps": [{ "direction": "IN", "labels": ["knows"], "properties": {}, "degree": 10000, "skip_degree": 100000 }, { "direction": "OUT", "labels": ["created"], "properties": {}, "degree": 10000, "skip_degree": 100000 }, { "direction": "IN", "labels": ["created"], "properties": {}, "degree": 10000, "skip_degree": 100000 }, { "direction": "OUT", "labels": ["created"], "properties": {}, "degree": 10000, "skip_degree": 100000 }], "capacity": 10000, "limit": 10, "with_vertex": True } code, res = Traverser().post_template_paths(json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(res['paths'], [{ 'objects': ['1:vadas', '1:marko', '2:lop', '1:josh', '2:ripple'] }])
def test_param_maxDepth_null(self): """ max_depth test :return: """ code, res = Traverser().all_shortest_path(param={"source": '"1:josh"', "target": '"1:marko"'}, auth=auth) print(code, res) self.assertEqual(code, 400, "code is error") self.assertEqual(res['message'], 'The max depth parameter must be > 0, but got 0', 'res is error')
def test_param_source_null(self): """ source test :return: """ code, res = Traverser().all_shortest_path(param={"target": '"1:josh"', "max_depth": 5}, auth=auth) print(code, res) self.assertEqual(code, 500, "code is error") self.assertEqual(res['message'], "The 'source vertex id' can't be null", "res is error")
def test_reqiured_params(self): """ :return: """ json = {'start': 'hzE65Y+y5YCZ', 'end': 'ijI66LW15aeo5aiYAA=='} code, res = Traverser().get_shard_vertex(json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(41, len(res['vertices']))
def test_direction_out(self): """ direction = out :return: """ param_json = {'source': '"1:贾宝玉"', 'max_depth': 1, 'direction': 'OUT'} code, res = Traverser().get_k_neighbor(param_json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(res, {'vertices': ['2:史湘云', '2:薛宝钗', '2:林黛玉']})
def test_direction_in(self): """ direction = in :return: """ param_json = {'source': '"1:贾宝玉"', 'max_depth': 1, 'direction': 'IN'} code, res = Traverser().get_k_neighbor(param_json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(res, {'vertices': ['2:王夫人']})
def test_reqiured_params(self): """ source、max_depth :return: """ param_json = {'source': '"1:marko"', 'target': '"2:ripple"', 'weight': '"weight"', 'with_vertex': True} code, res = Traverser().get_weighted_shortestPath(param_json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(res['path'], {'weight': 2.0, 'vertices': ['1:marko', '1:josh', '2:ripple']})
def test_direction_out(self): """ direction = out :return: """ param_json = {'source': '"1:贾代善"', 'target': '"1:贾宝玉"', 'max_depth': 5, 'direction': 'OUT'} code, res = Traverser().get_shortestPath(param_json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(res, {'path': ['1:贾代善', '1:贾政', '2:王夫人', '1:贾宝玉']})
def test_reqiured_params(self): """ source、max_depth :return: """ param_json = {'source': '"1:贾宝玉"', 'target': '"1:贾代善"', 'max_depth': 5} code, res = Traverser().get_shortestPath(param_json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(res, {'path': ['1:贾宝玉', '2:王夫人', '1:贾政', '1:贾代善']})
def test_reqiured_params(self): """ source、max_depth :return: """ param_json = {'source': '"1:贾宝玉"', 'max_depth': 1} code, res = Traverser().get_k_neighbor(param_json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(res, {'vertices': ['2:史湘云', '2:薛宝钗', '2:王夫人', '2:林黛玉']})
def test_param_source_valueInvalid(self): """ source test :return:I """ code, res = Traverser().all_shortest_path( param={"source": '"invalid"', "target": '"1:josh"', "max_depth": 5}, auth=auth ) print(code, res) self.assertEqual(code, 400, "code is error") self.assertEqual(res['message'], "The source vertex with id 'invalid' does not exist", "res is error")
def test_reqiured_params(self): """ source、max_depth :return: """ part_url = "?ids=%s&ids=%s&ids=%s&ids=%s" % ( 'S1:贾源>1>>S1:贾代善', 'S1:贾代善>1>>S1:贾赦', 'S1:贾政>5>>S2:王夫人', 'S1:贾宝玉>5>>S2:薛宝钗') code, res = Traverser().get_edges(part_url, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(4, len(res['edges']))
def test_param_maxDepth_typeInvalid(self): """ max_depth test :return: """ code, res = Traverser().all_shortest_path( param={"source": '"1:josh"', "target": '"1:marko"', "max_depth": '"5"'}, auth=auth ) print(code, res) self.assertEqual(code, 404, "code is error") self.assertEqual(res['cause'], 'java.lang.NumberFormatException: For input string: ""5""', 'res is error')
def test_param_maxDegree_valueInvalid(self): """ capacity: invalid test :return: """ code, res = Traverser().all_shortest_path( param={"source": '"1:josh"', "target": '"1:marko"', "max_depth": 4, "max_degree": 1}, auth=auth ) print(code, res) self.assertEqual(code, 200, "code is error") self.assertEqual(res['paths'], [], 'res is error')
def test_param_capacity_valueInvalid(self): """ capacity: invalid test :return: """ code, res = Traverser().all_shortest_path( param={"source": '"1:josh"', "target": '"1:marko"', "max_depth": 4, "capacity": 2}, auth=auth ) print(code, res) self.assertEqual(code, 400, "code is error") self.assertEqual(res['message'], 'The max degree must be < capacity', 'res is error')
def test_param_label_valueNotExist(self): """ label: not exist test :return: """ code, res = Traverser().all_shortest_path( param={"source": '"1:josh"', "target": '"1:marko"', "max_depth": 4, "label": "test"}, auth=auth ) print(code, res) self.assertEqual(code, 400, "code is error") self.assertEqual(res['message'], "Undefined edge label: 'test'", 'res is error')
def test_param_direction_valueOut(self): """ direction: out test :return: """ code, res = Traverser().all_shortest_path( param={"source": '"1:josh"', "target": '"1:marko"', "max_depth": 4, "direction": "OUT"}, auth=auth ) print(code, res) self.assertEqual(code, 200, "code is error") self.assertEqual(res, {'paths': []}, 'res is error')
def test_param_maxDepth_valueInvalid(self): """ max_depth test :return: """ code, res = Traverser().all_shortest_path( param={"source": '"1:josh"', "target": '"1:marko"', "max_depth": 3}, auth=auth ) print(code, res) self.assertEqual(code, 200, "code is error") self.assertEqual(res, {'paths': []}, 'res is error')
def test_reqiured_params(self): """ :return: """ json = { 'start': 'hzE65Y+y5YCZgggBAIcxOuWPsuWFrA==', 'end': 'ijI66LW15aeo5aiYgggEAIoyOui0vuaOouaYpQA=' } code, res = Traverser().get_shard_edge(json, auth=auth) print(code, res) print(len(res['edges'])) self.assertEqual(code, 200) self.assertEqual(51, len(res['edges']))
def test_param_source_typeInvalid(self): """ source test :return:I """ code, res = Traverser().all_shortest_path( param={"source": 'invalid', "target": '"1:josh"', "max_depth": 5}, auth=auth ) print(code, res) self.assertEqual(code, 400, "code is error") self.assertEqual( res['message'], "The vertex id must be formatted as Number/String/UUID, but got 'invalid'", "res is error" )
def test_param_skipDegree_valueInvalid(self): """ capacity: invalid test :return: """ code, res = Traverser().all_shortest_path( param={"source": '"1:josh"', "target": '"1:marko"', "max_depth": 4, "max_degree": 2, "skip_degree": 1}, auth=auth ) print(code, res) self.assertEqual(code, 400, "code is error") self.assertEqual( res['message'], "The skipped degree must be >= max degree, but got skipped degree '1' and max degree '2'", 'res is error' )
def test_reqiured_params(self): """ :return: """ json = {'split_size': 1048576} code, res = Traverser().get_vertex_shard(json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual( res, { 'shards': [{ 'start': 'hzE65Y+y5YCZ', 'end': 'ijI66LW15aeo5aiYAA==', 'length': 0 }] })
def test_param_skipDegree_valueNormal(self): """ capacity: invalid test :return: """ code, res = Traverser().all_shortest_path( param={"source": '"1:josh"', "target": '"1:marko"', "max_depth": 4, "max_degree": 2, "skip_degree": 4}, auth=auth ) print(code, res) self.assertEqual(code, 200, "code is error") self.assertEqual( res['paths'], [{'objects': ['1:josh', '1:peter', '2:lop', '1:vadas', '1:marko']}], 'res is error' )
def test_reqiured_params(self): """ :return: """ json = {'split_size': 1048576} code, res = Traverser().get_edge_shard(json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual( res, { 'shards': [{ 'start': 'hzE65Y+y5YCZgggBAIcxOuWPsuWFrA==', 'end': 'ijI66LW15aeo5aiYgggEAIoyOui0vuaOouaYpQA=', 'length': 0 }] })
def test_reqiured_params(self): """ source、max_depth :return: """ json = { "sources": { "ids": [], "label": "person", "properties": { "name": "marko" } }, "steps": [{ "direction": "OUT", "labels": ["knows"], "weight_by": "weight", "degree": -1 }, { "direction": "OUT", "labels": ["created"], "default_weight": 8, "degree": -1, "sample": -1 }], "sort_by": "INCR", "with_vertex": True, "capacity": -1, "limit": -1 } code, res = Traverser().post_customized_paths(json, auth=auth) print(code, res) self.assertEqual(code, 200) self.assertEqual(res['paths'], [{ 'objects': ['1:marko', '1:josh', '2:ripple'], 'weights': [1.0, 8.0] }, { 'objects': ['1:marko', '1:josh', '2:lop'], 'weights': [1.0, 8.0] }])
def test_param_direction_valueBoth(self): """ direction: both test :return: """ code, res = Traverser().all_shortest_path( param={"source": '"1:josh"', "target": '"1:marko"', "max_depth": 4, "direction": "BOTH"}, auth=auth ) print(code, res) self.assertEqual(code, 200, "code is error") self.assertEqual( res['paths'], [ {'objects': ['1:josh', '1:peter', '2:lop', '1:vadas', '1:marko']}, {'objects': ['1:josh', '1:peter', '2:ripple', '1:vadas', '1:marko']} ], 'res is error' )
def test_param_normal(self): """ source test :return: """ code, res = Traverser().all_shortest_path( param={"source": '"1:marko"', "target": '"1:josh"', "max_depth": 5}, auth=auth ) print(code, res) self.assertEqual(code, 200, "code is error") self.assertEqual( res['paths'], [ {'objects': ['1:marko', '1:vadas', '2:ripple', '1:peter', '1:josh']}, {'objects': ['1:marko', '1:vadas', '2:lop', '1:peter', '1:josh']} ], "res is error" )