1
|
|
|
import os |
2
|
|
|
|
3
|
|
|
import config_module |
4
|
|
|
import pytest |
5
|
|
|
|
6
|
|
|
import goblin |
7
|
|
|
from goblin import driver, exception |
8
|
|
|
|
9
|
|
|
dirname = os.path.dirname(os.path.dirname(__file__)) |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
@pytest.fixture(params=[0, 1]) |
13
|
|
|
def conf_module(request): |
14
|
|
|
if request.param: |
15
|
|
|
return 'config_module' |
16
|
|
|
else: |
17
|
|
|
return config_module |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def test_cluster_default_config(event_loop): |
21
|
|
|
cluster = driver.Cluster(event_loop) |
22
|
|
|
assert cluster.config['scheme'] == 'ws' |
23
|
|
|
assert cluster.config['hosts'] == ['localhost'] |
24
|
|
|
assert cluster.config['port'] == 8182 |
25
|
|
|
assert cluster.config['ssl_certfile'] == '' |
26
|
|
|
assert cluster.config['ssl_keyfile'] == '' |
27
|
|
|
assert cluster.config['ssl_password'] == '' |
28
|
|
|
assert cluster.config['username'] == '' |
29
|
|
|
assert cluster.config['password'] == '' |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
@pytest.mark.asyncio |
33
|
|
|
async def test_app_default_config(event_loop): |
34
|
|
|
cluster = driver.Cluster(event_loop) |
35
|
|
|
app = goblin.Goblin(cluster) |
36
|
|
|
assert app.config['scheme'] == 'ws' |
37
|
|
|
assert app.config['hosts'] == ['localhost'] |
38
|
|
|
assert app.config['port'] == 8182 |
39
|
|
|
assert app.config['ssl_certfile'] == '' |
40
|
|
|
assert app.config['ssl_keyfile'] == '' |
41
|
|
|
assert app.config['ssl_password'] == '' |
42
|
|
|
assert app.config['username'] == '' |
43
|
|
|
assert app.config['password'] == '' |
44
|
|
|
assert issubclass(app.config['message_serializer'], |
45
|
|
|
driver.GraphSONMessageSerializer) |
46
|
|
|
await app.close() |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
def test_cluster_custom_config(event_loop, cluster_class): |
50
|
|
|
cluster = cluster_class( |
51
|
|
|
event_loop, username='dave', password='mypass', hosts=['127.0.0.1']) |
52
|
|
|
assert cluster.config['scheme'] == 'ws' |
53
|
|
|
assert cluster.config['hosts'] == ['127.0.0.1'] |
54
|
|
|
assert cluster.config['port'] == 8182 |
55
|
|
|
assert cluster.config['ssl_certfile'] == '' |
56
|
|
|
assert cluster.config['ssl_keyfile'] == '' |
57
|
|
|
assert cluster.config['ssl_password'] == '' |
58
|
|
|
assert cluster.config['username'] == 'dave' |
59
|
|
|
assert cluster.config['password'] == 'mypass' |
60
|
|
|
assert issubclass(cluster.config['message_serializer'], |
61
|
|
|
driver.GraphSONMessageSerializer) |
62
|
|
|
|
63
|
|
|
|
64
|
|
View Code Duplication |
def test_cluster_config_from_json(event_loop, cluster_class): |
|
|
|
|
65
|
|
|
cluster = cluster_class(event_loop) |
66
|
|
|
cluster.config_from_file(dirname + '/tests/config/config.json') |
67
|
|
|
assert cluster.config['scheme'] == 'wss' |
68
|
|
|
assert cluster.config['hosts'] == ['localhost'] |
69
|
|
|
assert cluster.config['port'] == 8182 |
70
|
|
|
assert cluster.config['ssl_certfile'] == '' |
71
|
|
|
assert cluster.config['ssl_keyfile'] == '' |
72
|
|
|
assert cluster.config['ssl_password'] == '' |
73
|
|
|
assert cluster.config['username'] == 'dave' |
74
|
|
|
assert cluster.config['password'] == 'mypass' |
75
|
|
|
|
76
|
|
|
assert issubclass(cluster.config['message_serializer'], |
77
|
|
|
driver.GraphSONMessageSerializer) |
78
|
|
|
|
79
|
|
|
|
80
|
|
View Code Duplication |
def test_cluster_config_from_yaml(event_loop, cluster_class): |
|
|
|
|
81
|
|
|
cluster = cluster_class(event_loop) |
82
|
|
|
cluster.config_from_file(dirname + '/tests/config/config.yml') |
83
|
|
|
assert cluster.config['scheme'] == 'wss' |
84
|
|
|
assert cluster.config['hosts'] == ['localhost'] |
85
|
|
|
assert cluster.config['port'] == 8183 |
86
|
|
|
assert cluster.config['ssl_certfile'] == '' |
87
|
|
|
assert cluster.config['ssl_keyfile'] == '' |
88
|
|
|
assert cluster.config['ssl_password'] == '' |
89
|
|
|
assert cluster.config['username'] == '' |
90
|
|
|
assert cluster.config['password'] == '' |
91
|
|
|
assert issubclass(cluster.config['message_serializer'], |
92
|
|
|
driver.GraphSONMessageSerializer) |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
def test_cluster_config_from_module(event_loop, cluster_class, conf_module): |
96
|
|
|
cluster = cluster_class(event_loop) |
97
|
|
|
cluster.config_from_module(conf_module) |
98
|
|
|
assert cluster.config['scheme'] == 'wss' |
99
|
|
|
assert cluster.config['hosts'] == ['localhost'] |
100
|
|
|
assert cluster.config['port'] == 8183 |
101
|
|
|
assert cluster.config['message_serializer'] is \ |
102
|
|
|
driver.GraphSONMessageSerializer |
103
|
|
|
|
104
|
|
|
|
105
|
|
View Code Duplication |
@pytest.mark.asyncio |
|
|
|
|
106
|
|
|
async def test_app_config_from_json(app): |
107
|
|
|
app.config_from_file(dirname + '/tests/config/config.json') |
108
|
|
|
assert app.config['scheme'] == 'wss' |
109
|
|
|
assert app.config['hosts'] == ['localhost'] |
110
|
|
|
assert app.config['port'] == 8182 |
111
|
|
|
assert app.config['ssl_certfile'] == '' |
112
|
|
|
assert app.config['ssl_keyfile'] == '' |
113
|
|
|
assert app.config['ssl_password'] == '' |
114
|
|
|
assert app.config['username'] == 'dave' |
115
|
|
|
assert app.config['password'] == 'mypass' |
116
|
|
|
|
117
|
|
|
assert issubclass(app.config['message_serializer'], |
118
|
|
|
driver.GraphSONMessageSerializer) |
119
|
|
|
await app.close() |
120
|
|
|
|
121
|
|
|
|
122
|
|
View Code Duplication |
@pytest.mark.asyncio |
|
|
|
|
123
|
|
|
async def test_app_config_from_yaml(app): |
124
|
|
|
app.config_from_file(dirname + '/tests/config/config.yml') |
125
|
|
|
assert app.config['scheme'] == 'wss' |
126
|
|
|
assert app.config['hosts'] == ['localhost'] |
127
|
|
|
assert app.config['port'] == 8183 |
128
|
|
|
assert app.config['ssl_certfile'] == '' |
129
|
|
|
assert app.config['ssl_keyfile'] == '' |
130
|
|
|
assert app.config['ssl_password'] == '' |
131
|
|
|
assert app.config['username'] == '' |
132
|
|
|
assert app.config['password'] == '' |
133
|
|
|
assert issubclass(app.config['message_serializer'], |
134
|
|
|
driver.GraphSONMessageSerializer) |
135
|
|
|
await app.close() |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
@pytest.mark.asyncio |
139
|
|
|
async def test_app_config_from_module(app, conf_module): |
140
|
|
|
app.config_from_module(conf_module) |
141
|
|
|
assert app.config['scheme'] == 'wss' |
142
|
|
|
assert app.config['hosts'] == ['localhost'] |
143
|
|
|
assert app.config['port'] == 8183 |
144
|
|
|
assert app.config['message_serializer'] is driver.GraphSONMessageSerializer |
145
|
|
|
await app.close() |
146
|
|
|
|