Skip to content

Commit 0609568

Browse files
committed
Fix tests
1 parent 240f7b3 commit 0609568

File tree

5 files changed

+67
-28
lines changed

5 files changed

+67
-28
lines changed

node_cli/core/node.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from node_cli.configs.cli_logger import LOG_DATA_PATH as CLI_LOG_DATA_PATH
4747

4848
from node_cli.core.nftables import configure_nftables
49-
# from node_cli.core.iptables import configure_iptables
5049
from node_cli.core.host import (
5150
is_node_inited, save_env_params, get_flask_secret_key
5251
)

scripts/run_nftables_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ docker run \
1414
-e GLOBAL_SKALE_DIR="$PROJECT_DIR/tests/etc/skale" \
1515
-e DOTENV_FILEPATH='tests/test-env' \
1616
--cap-add=NET_ADMIN --cap-add=NET_RAW \
17-
--name ncli-tester ncli-tester py.test -v tests/core/migration_test.py tests/core/nftables_test.py $@
17+
--name ncli-tester ncli-tester py.test tests/core/migration_test.py tests/core/nftables_test.py $@
1818

scripts/run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ LVMPY_LOG_DIR="$PROJECT_DIR/tests/" \
88
TEST_HOME_DIR="$PROJECT_DIR/tests/" \
99
GLOBAL_SKALE_DIR="$PROJECT_DIR/tests/etc/skale" \
1010
DOTENV_FILEPATH='tests/test-env' \
11-
py.test -v --cov=$PROJECT_DIR/ --ignore=tests/core/nftables_test.py --ignore=tests/core/migration_test.py tests $@
11+
py.test --cov=$PROJECT_DIR/ --ignore=tests/core/nftables_test.py --ignore=tests/core/migration_test.py tests $@

tests/cli/node_test.py

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
)
4141
from node_cli.utils.exit_codes import CLIExitCodes
4242
from node_cli.utils.helper import init_default_logger
43+
from node_cli.utils.meta import CliMeta
4344

4445
from tests.helper import (
4546
response_mock,
@@ -84,7 +85,9 @@ def test_register_node_with_error(resource_alloc, mocked_g_config):
8485
)
8586
assert result.exit_code == 3
8687
assert (
87-
result.output == f'Command failed with following errors:\n--------------------------------------------------\nStrange error\n--------------------------------------------------\nYou 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--------------------------------------------------\nStrange error\n--------------------------------------------------\nYou can find more info in {G_CONF_HOME}.skale/.skale-cli-log/debug-node-cli.log\n'
90+
) # noqa
8891

8992

9093
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):
98101
input='0.0.0.0\n',
99102
)
100103
assert result.exit_code == 0
101-
assert result.output == 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager.\nFor more info run < skale node info >\n' # noqa
104+
assert (
105+
result.output
106+
== 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager.\nFor more info run < skale node info >\n'
107+
) # noqa
102108

103109

104110
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):
112118
input='0.0.0.0\n',
113119
)
114120
assert result.exit_code == 0
115-
assert result.output == 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager.\nFor more info run < skale node info >\n' # noqa
121+
assert (
122+
result.output
123+
== 'Enter node public IP: 0.0.0.0\nNode registered in SKALE manager.\nFor more info run < skale node info >\n'
124+
) # noqa
116125

117126

118127
def test_register_with_no_alloc(mocked_g_config):
@@ -125,7 +134,10 @@ def test_register_with_no_alloc(mocked_g_config):
125134
input='0.0.0.0\n',
126135
)
127136
assert result.exit_code == 8
128-
assert result.output == f"Enter node public IP: 0.0.0.0\nCommand failed with following errors:\n--------------------------------------------------\nNode hasn't been inited before.\nYou should run < skale node init >\n--------------------------------------------------\nYou 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\nCommand failed with following errors:\n--------------------------------------------------\nNode hasn't been inited before.\nYou should run < skale node init >\n--------------------------------------------------\nYou can find more info in {G_CONF_HOME}.skale/.skale-cli-log/debug-node-cli.log\n"
140+
) # noqa
129141

130142

131143
def test_node_info_node_info():
@@ -150,7 +162,10 @@ def test_node_info_node_info():
150162
resp_mock = response_mock(requests.codes.ok, json_data={'payload': payload, 'status': 'ok'})
151163
result = run_command_mock('node_cli.utils.helper.requests.get', resp_mock, node_info)
152164
assert result.exit_code == 0
153-
assert result.output == '--------------------------------------------------\nNode info\nName: test\nID: 32\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nDomain name: skale.test\nStatus: Active\n--------------------------------------------------\n' # noqa
165+
assert (
166+
result.output
167+
== '--------------------------------------------------\nNode info\nName: test\nID: 32\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nDomain name: skale.test\nStatus: Active\n--------------------------------------------------\n'
168+
) # noqa
154169

155170

156171
def test_node_info_node_info_not_created():
@@ -200,7 +215,10 @@ def test_node_info_node_info_frozen():
200215
resp_mock = response_mock(requests.codes.ok, json_data={'payload': payload, 'status': 'ok'})
201216
result = run_command_mock('node_cli.utils.helper.requests.get', resp_mock, node_info)
202217
assert result.exit_code == 0
203-
assert result.output == '--------------------------------------------------\nNode info\nName: test\nID: 32\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nDomain name: skale.test\nStatus: Frozen\n--------------------------------------------------\n' # noqa
218+
assert (
219+
result.output
220+
== '--------------------------------------------------\nNode info\nName: test\nID: 32\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nDomain name: skale.test\nStatus: Frozen\n--------------------------------------------------\n'
221+
) # noqa
204222

205223

206224
def test_node_info_node_info_left():
@@ -225,7 +243,10 @@ def test_node_info_node_info_left():
225243
resp_mock = response_mock(requests.codes.ok, json_data={'payload': payload, 'status': 'ok'})
226244
result = run_command_mock('node_cli.utils.helper.requests.get', resp_mock, node_info)
227245
assert result.exit_code == 0
228-
assert result.output == '--------------------------------------------------\nNode info\nName: test\nID: 32\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nDomain name: skale.test\nStatus: Left\n--------------------------------------------------\n' # noqa
246+
assert (
247+
result.output
248+
== '--------------------------------------------------\nNode info\nName: test\nID: 32\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nDomain name: skale.test\nStatus: Left\n--------------------------------------------------\n'
249+
) # noqa
229250

230251

231252
def test_node_info_node_info_leaving():
@@ -250,7 +271,10 @@ def test_node_info_node_info_leaving():
250271
resp_mock = response_mock(requests.codes.ok, json_data={'payload': payload, 'status': 'ok'})
251272
result = run_command_mock('node_cli.utils.helper.requests.get', resp_mock, node_info)
252273
assert result.exit_code == 0
253-
assert result.output == '--------------------------------------------------\nNode info\nName: test\nID: 32\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nDomain name: skale.test\nStatus: Leaving\n--------------------------------------------------\n' # noqa
274+
assert (
275+
result.output
276+
== '--------------------------------------------------\nNode info\nName: test\nID: 32\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nDomain name: skale.test\nStatus: Leaving\n--------------------------------------------------\n'
277+
) # noqa
254278

255279

256280
def test_node_info_node_info_in_maintenance():
@@ -275,7 +299,10 @@ def test_node_info_node_info_in_maintenance():
275299
resp_mock = response_mock(requests.codes.ok, json_data={'payload': payload, 'status': 'ok'})
276300
result = run_command_mock('node_cli.utils.helper.requests.get', resp_mock, node_info)
277301
assert result.exit_code == 0
278-
assert result.output == '--------------------------------------------------\nNode info\nName: test\nID: 32\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nDomain name: skale.test\nStatus: In Maintenance\n--------------------------------------------------\n' # noqa
302+
assert (
303+
result.output
304+
== '--------------------------------------------------\nNode info\nName: test\nID: 32\nIP: 0.0.0.0\nPublic IP: 1.1.1.1\nPort: 10001\nDomain name: skale.test\nStatus: In Maintenance\n--------------------------------------------------\n'
305+
) # noqa
279306

280307

281308
def test_node_signature():
@@ -306,7 +333,10 @@ def test_restore(mocked_g_config):
306333
'subprocess.run', new=subprocess_run_mock
307334
), patch('node_cli.core.resources.get_disk_size', return_value=BIG_DISK_SIZE), patch(
308335
'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'):
310340
result = run_command(restore_node, [backup_path, './tests/test-env'])
311341
assert result.exit_code == 0
312342
assert 'Node is restored from backup\n' in result.output # noqa
@@ -325,7 +355,10 @@ def test_restore_no_snapshot(mocked_g_config):
325355
'subprocess.run', new=subprocess_run_mock
326356
), patch('node_cli.core.resources.get_disk_size', return_value=BIG_DISK_SIZE), patch(
327357
'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'):
329362
result = run_command(restore_node, [backup_path, './tests/test-env', '--no-snapshot'])
330363
assert result.exit_code == 0
331364
assert 'Node is restored from backup\n' in result.output # noqa
@@ -392,7 +425,7 @@ def test_turn_on_maintenance_off(mocked_g_config):
392425
'node_cli.core.node.get_flask_secret_key'
393426
), mock.patch('node_cli.core.node.turn_on_op'), mock.patch(
394427
'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):
396429
result = run_command_mock(
397430
'node_cli.utils.helper.requests.post',
398431
resp_mock,
@@ -424,14 +457,17 @@ def test_set_domain_name():
424457

425458

426459
def test_node_version(meta_file_v2):
427-
result = run_command(version)
428-
assert result.exit_code == 0
429-
assert result.output == '--------------------------------------------------\nVersion: 0.1.1\nConfig Stream: develop\nLvmpy 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+
== '--------------------------------------------------\nVersion: 0.1.1\nConfig Stream: develop\nLvmpy stream: 1.1.2\n--------------------------------------------------\n'
466+
) # noqa
430467

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

tests/core/core_node_test.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
import pytest
1010
import requests
1111

12-
from node_cli.cli import __version__
13-
1412
from node_cli.configs import NODE_DATA_PATH
1513
from node_cli.configs.resource_allocation import RESOURCE_ALLOCATION_FILEPATH
1614
from node_cli.core.node import BASE_CONTAINERS_AMOUNT, is_base_containers_alive
1715
from node_cli.core.node import init, pack_dir, update, is_update_safe, repair_sync
16+
from node_cli.utils.meta import CliMeta
1817

1918
from tests.helper import response_mock, safe_update_api_response, subprocess_run_mock
2019
from tests.resources_test import BIG_DISK_SIZE
@@ -170,7 +169,12 @@ def test_update_node(mocked_g_config, resource_file):
170169
'node_cli.utils.helper.post_request', resp_mock
171170
), mock.patch('node_cli.core.resources.get_disk_size', return_value=BIG_DISK_SIZE), mock.patch(
172171
'node_cli.core.host.init_data_dir'
173-
), mock.patch('node_cli.core.node.get_meta_info', return_value={'version': __version__}):
172+
), mock.patch(
173+
'node_cli.core.node.get_meta_info',
174+
return_value=CliMeta(
175+
version='2.5.0', config_stream='3.0.2'
176+
)
177+
):
174178
with mock.patch( 'node_cli.utils.helper.requests.get', return_value=safe_update_api_response()): # noqa
175179
result = update(env_filepath, pull_config_for_schain=None)
176180
assert result is None

0 commit comments

Comments
 (0)