40
40
)
41
41
from node_cli .utils .exit_codes import CLIExitCodes
42
42
from node_cli .utils .helper import init_default_logger
43
+ from node_cli .utils .meta import CliMeta
43
44
44
45
from tests .helper import (
45
46
response_mock ,
@@ -84,7 +85,9 @@ def test_register_node_with_error(resource_alloc, mocked_g_config):
84
85
)
85
86
assert result .exit_code == 3
86
87
assert (
87
- result .output == f'Command failed with following errors:\n --------------------------------------------------\n Strange error\n --------------------------------------------------\n You can find more info in { G_CONF_HOME } .skale/.skale-cli-log/debug-node-cli.log\n ' ) # noqa
88
+ result .output
89
+ == f'Command failed with following errors:\n --------------------------------------------------\n Strange error\n --------------------------------------------------\n You can find more info in { G_CONF_HOME } .skale/.skale-cli-log/debug-node-cli.log\n '
90
+ ) # noqa
88
91
89
92
90
93
def test_register_node_with_prompted_ip (resource_alloc , mocked_g_config ):
@@ -98,7 +101,10 @@ def test_register_node_with_prompted_ip(resource_alloc, mocked_g_config):
98
101
input = '0.0.0.0\n ' ,
99
102
)
100
103
assert result .exit_code == 0
101
- assert result .output == 'Enter node public IP: 0.0.0.0\n Node registered in SKALE manager.\n For more info run < skale node info >\n ' # noqa
104
+ assert (
105
+ result .output
106
+ == 'Enter node public IP: 0.0.0.0\n Node registered in SKALE manager.\n For more info run < skale node info >\n '
107
+ ) # noqa
102
108
103
109
104
110
def test_register_node_with_default_port (resource_alloc , mocked_g_config ):
@@ -112,7 +118,10 @@ def test_register_node_with_default_port(resource_alloc, mocked_g_config):
112
118
input = '0.0.0.0\n ' ,
113
119
)
114
120
assert result .exit_code == 0
115
- assert result .output == 'Enter node public IP: 0.0.0.0\n Node registered in SKALE manager.\n For more info run < skale node info >\n ' # noqa
121
+ assert (
122
+ result .output
123
+ == 'Enter node public IP: 0.0.0.0\n Node registered in SKALE manager.\n For more info run < skale node info >\n '
124
+ ) # noqa
116
125
117
126
118
127
def test_register_with_no_alloc (mocked_g_config ):
@@ -125,7 +134,10 @@ def test_register_with_no_alloc(mocked_g_config):
125
134
input = '0.0.0.0\n ' ,
126
135
)
127
136
assert result .exit_code == 8
128
- assert result .output == f"Enter node public IP: 0.0.0.0\n Command failed with following errors:\n --------------------------------------------------\n Node hasn't been inited before.\n You should run < skale node init >\n --------------------------------------------------\n You can find more info in { G_CONF_HOME } .skale/.skale-cli-log/debug-node-cli.log\n " # noqa
137
+ assert (
138
+ result .output
139
+ == f"Enter node public IP: 0.0.0.0\n Command failed with following errors:\n --------------------------------------------------\n Node hasn't been inited before.\n You should run < skale node init >\n --------------------------------------------------\n You can find more info in { G_CONF_HOME } .skale/.skale-cli-log/debug-node-cli.log\n "
140
+ ) # noqa
129
141
130
142
131
143
def test_node_info_node_info ():
@@ -150,7 +162,10 @@ def test_node_info_node_info():
150
162
resp_mock = response_mock (requests .codes .ok , json_data = {'payload' : payload , 'status' : 'ok' })
151
163
result = run_command_mock ('node_cli.utils.helper.requests.get' , resp_mock , node_info )
152
164
assert result .exit_code == 0
153
- assert result .output == '--------------------------------------------------\n Node info\n Name: test\n ID: 32\n IP: 0.0.0.0\n Public IP: 1.1.1.1\n Port: 10001\n Domain name: skale.test\n Status: Active\n --------------------------------------------------\n ' # noqa
165
+ assert (
166
+ result .output
167
+ == '--------------------------------------------------\n Node info\n Name: test\n ID: 32\n IP: 0.0.0.0\n Public IP: 1.1.1.1\n Port: 10001\n Domain name: skale.test\n Status: Active\n --------------------------------------------------\n '
168
+ ) # noqa
154
169
155
170
156
171
def test_node_info_node_info_not_created ():
@@ -200,7 +215,10 @@ def test_node_info_node_info_frozen():
200
215
resp_mock = response_mock (requests .codes .ok , json_data = {'payload' : payload , 'status' : 'ok' })
201
216
result = run_command_mock ('node_cli.utils.helper.requests.get' , resp_mock , node_info )
202
217
assert result .exit_code == 0
203
- assert result .output == '--------------------------------------------------\n Node info\n Name: test\n ID: 32\n IP: 0.0.0.0\n Public IP: 1.1.1.1\n Port: 10001\n Domain name: skale.test\n Status: Frozen\n --------------------------------------------------\n ' # noqa
218
+ assert (
219
+ result .output
220
+ == '--------------------------------------------------\n Node info\n Name: test\n ID: 32\n IP: 0.0.0.0\n Public IP: 1.1.1.1\n Port: 10001\n Domain name: skale.test\n Status: Frozen\n --------------------------------------------------\n '
221
+ ) # noqa
204
222
205
223
206
224
def test_node_info_node_info_left ():
@@ -225,7 +243,10 @@ def test_node_info_node_info_left():
225
243
resp_mock = response_mock (requests .codes .ok , json_data = {'payload' : payload , 'status' : 'ok' })
226
244
result = run_command_mock ('node_cli.utils.helper.requests.get' , resp_mock , node_info )
227
245
assert result .exit_code == 0
228
- assert result .output == '--------------------------------------------------\n Node info\n Name: test\n ID: 32\n IP: 0.0.0.0\n Public IP: 1.1.1.1\n Port: 10001\n Domain name: skale.test\n Status: Left\n --------------------------------------------------\n ' # noqa
246
+ assert (
247
+ result .output
248
+ == '--------------------------------------------------\n Node info\n Name: test\n ID: 32\n IP: 0.0.0.0\n Public IP: 1.1.1.1\n Port: 10001\n Domain name: skale.test\n Status: Left\n --------------------------------------------------\n '
249
+ ) # noqa
229
250
230
251
231
252
def test_node_info_node_info_leaving ():
@@ -250,7 +271,10 @@ def test_node_info_node_info_leaving():
250
271
resp_mock = response_mock (requests .codes .ok , json_data = {'payload' : payload , 'status' : 'ok' })
251
272
result = run_command_mock ('node_cli.utils.helper.requests.get' , resp_mock , node_info )
252
273
assert result .exit_code == 0
253
- assert result .output == '--------------------------------------------------\n Node info\n Name: test\n ID: 32\n IP: 0.0.0.0\n Public IP: 1.1.1.1\n Port: 10001\n Domain name: skale.test\n Status: Leaving\n --------------------------------------------------\n ' # noqa
274
+ assert (
275
+ result .output
276
+ == '--------------------------------------------------\n Node info\n Name: test\n ID: 32\n IP: 0.0.0.0\n Public IP: 1.1.1.1\n Port: 10001\n Domain name: skale.test\n Status: Leaving\n --------------------------------------------------\n '
277
+ ) # noqa
254
278
255
279
256
280
def test_node_info_node_info_in_maintenance ():
@@ -275,7 +299,10 @@ def test_node_info_node_info_in_maintenance():
275
299
resp_mock = response_mock (requests .codes .ok , json_data = {'payload' : payload , 'status' : 'ok' })
276
300
result = run_command_mock ('node_cli.utils.helper.requests.get' , resp_mock , node_info )
277
301
assert result .exit_code == 0
278
- assert result .output == '--------------------------------------------------\n Node info\n Name: test\n ID: 32\n IP: 0.0.0.0\n Public IP: 1.1.1.1\n Port: 10001\n Domain name: skale.test\n Status: In Maintenance\n --------------------------------------------------\n ' # noqa
302
+ assert (
303
+ result .output
304
+ == '--------------------------------------------------\n Node info\n Name: test\n ID: 32\n IP: 0.0.0.0\n Public IP: 1.1.1.1\n Port: 10001\n Domain name: skale.test\n Status: In Maintenance\n --------------------------------------------------\n '
305
+ ) # noqa
279
306
280
307
281
308
def test_node_signature ():
@@ -306,7 +333,10 @@ def test_restore(mocked_g_config):
306
333
'subprocess.run' , new = subprocess_run_mock
307
334
), patch ('node_cli.core.resources.get_disk_size' , return_value = BIG_DISK_SIZE ), patch (
308
335
'node_cli.utils.decorators.is_node_inited' , return_value = False
309
- ):
336
+ ), patch (
337
+ 'node_cli.core.node.get_meta_info' ,
338
+ return_value = CliMeta (version = '2.4.0' , config_stream = '3.0.2' ),
339
+ ), patch ('node_cli.core.node.configure_firewall_rules' ):
310
340
result = run_command (restore_node , [backup_path , './tests/test-env' ])
311
341
assert result .exit_code == 0
312
342
assert 'Node is restored from backup\n ' in result .output # noqa
@@ -325,7 +355,10 @@ def test_restore_no_snapshot(mocked_g_config):
325
355
'subprocess.run' , new = subprocess_run_mock
326
356
), patch ('node_cli.core.resources.get_disk_size' , return_value = BIG_DISK_SIZE ), patch (
327
357
'node_cli.utils.decorators.is_node_inited' , return_value = False
328
- ):
358
+ ), patch (
359
+ 'node_cli.core.node.get_meta_info' ,
360
+ return_value = CliMeta (version = '2.4.0' , config_stream = '3.0.2' ),
361
+ ), patch ('node_cli.core.node.configure_firewall_rules' ):
329
362
result = run_command (restore_node , [backup_path , './tests/test-env' , '--no-snapshot' ])
330
363
assert result .exit_code == 0
331
364
assert 'Node is restored from backup\n ' in result .output # noqa
@@ -392,7 +425,7 @@ def test_turn_on_maintenance_off(mocked_g_config):
392
425
'node_cli.core.node.get_flask_secret_key'
393
426
), mock .patch ('node_cli.core.node.turn_on_op' ), mock .patch (
394
427
'node_cli.core.node.is_base_containers_alive'
395
- ), mock .patch ('node_cli.core.node .is_node_inited' , return_value = True ):
428
+ ), mock .patch ('node_cli.utils.decorators .is_node_inited' , return_value = True ):
396
429
result = run_command_mock (
397
430
'node_cli.utils.helper.requests.post' ,
398
431
resp_mock ,
@@ -424,14 +457,17 @@ def test_set_domain_name():
424
457
425
458
426
459
def test_node_version (meta_file_v2 ):
427
- result = run_command (version )
428
- assert result .exit_code == 0
429
- assert result .output == '--------------------------------------------------\n Version: 0.1.1\n Config Stream: develop\n Lvmpy stream: 1.1.2\n --------------------------------------------------\n ' # noqa
460
+ with mock .patch ('node_cli.utils.decorators.is_node_inited' , return_value = True ):
461
+ result = run_command (version )
462
+ assert result .exit_code == 0
463
+ assert (
464
+ result .output
465
+ == '--------------------------------------------------\n Version: 0.1.1\n Config Stream: develop\n Lvmpy stream: 1.1.2\n --------------------------------------------------\n '
466
+ ) # noqa
430
467
431
- result = run_command (version , ['--json' ])
432
- print (repr (result .output ))
433
- assert result .exit_code == 0
434
- assert (
435
- result .output
436
- == "{'version': '0.1.1', 'config_stream': 'develop', 'docker_lvmpy_stream': '1.1.2'}\n "
437
- ) # noqa
468
+ result = run_command (version , ['--json' ])
469
+ assert result .exit_code == 0
470
+ assert (
471
+ result .output
472
+ == "{'version': '0.1.1', 'config_stream': 'develop', 'docker_lvmpy_stream': '1.1.2'}\n "
473
+ ) # noqa
0 commit comments