blob: c1ed25586db1dd960daa8914a139731004151b97 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
"""
Various test utilities
"""
import db_controller as dbc
from model.model import Link
from neo4j_test_util import gen_random_name
from neo4j_util import rand_id
from rz_kernel import RZ_Kernel
from rz_mesh import init_ws_interface
from rz_server import init_webapp
def init_test_db_controller(cfg):
ret = dbc.DB_Controller(cfg)
return ret
def init_test_ws_server(cfg, db_ctl):
"""
Initialize a test websocket server
@param db_ctl: an initialized DB_Controller
"""
kernel = RZ_Kernel()
webapp = init_webapp(cfg, kernel, db_ctl)
ws_srv = init_ws_interface(cfg, webapp)
return ws_srv
def generate_random_node_dict(n_type, nid=None):
"""
@param n_type: is converted to a label set
@return: a dict based node object representation and the generated node id
"""
if None == nid:
nid = rand_id()
return {'__label_set': [n_type],
'id': nid,
'name': gen_random_name() }, nid
def generate_random_link_dict(l_type, src_id, dst_id, lid=None):
"""
@param l_type: is converted to a single item type array
@return: a dict based node object representation and the generated node id
"""
if None == lid:
lid = rand_id()
ret_dict = Link.link_ptr(src_id, dst_id)
ret_dict['__type'] = [l_type]
ret_dict['id'] = lid
return ret_dict, lid
|