1818# along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
2020import pathlib
21-
2221import mock
2322from unittest .mock import MagicMock , patch
23+
2424import requests
2525import logging
26+ import pytest
2627
27- from node_cli .configs import SKALE_DIR , G_CONF_HOME
28+ from node_cli .utils .node_type import NodeType
29+
30+ from node_cli .configs import INIT_ENV_FILEPATH , SKALE_DIR , G_CONF_HOME
2831from node_cli .cli .node import (
2932 node_info ,
3033 register_node ,
@@ -321,14 +324,20 @@ def test_backup():
321324 assert 'Backup archive succesfully created ' in result .output
322325
323326
324- def test_restore (mocked_g_config ):
327+ @pytest .mark .parametrize ("node_type,test_user_conf" , [
328+ (NodeType .REGULAR , "regular_user_conf" ),
329+ (NodeType .MIRAGE , "mirage_user_conf" ),
330+ (NodeType .SYNC , "sync_user_conf" )
331+ ])
332+ def test_restore (request , node_type , test_user_conf , mocked_g_config , tmp_path ):
325333 pathlib .Path (SKALE_DIR ).mkdir (parents = True , exist_ok = True )
326- result = run_command (backup_node , ['/tmp' ])
334+ result = run_command (backup_node , [tmp_path ])
327335 backup_path = result .output .replace ('Backup archive successfully created: ' , '' ).replace (
328336 '\n ' , ''
329337 )
330338
331339 with (
340+ patch ('node_cli.cli.node.TYPE' , node_type ),
332341 patch ('node_cli.core.node.restore_op' , MagicMock ()) as mock_restore_op ,
333342 patch ('subprocess.run' , new = subprocess_run_mock ),
334343 patch ('node_cli.core.resources.get_disk_size' , return_value = BIG_DISK_SIZE ),
@@ -337,44 +346,20 @@ def test_restore(mocked_g_config):
337346 'node_cli.core.node.CliMetaManager.get_meta_info' ,
338347 return_value = CliMeta (version = '2.4.0' , config_stream = '3.0.2' ),
339348 ),
340- # patch(
341- # 'node_cli.core.node.get_meta_info',
342- # return_value=CliMeta(version='2.4.0', config_stream='3.0.2'),
343- # ),
344349 patch ('node_cli.operations.base.configure_nftables' ),
345- patch ('node_cli.configs.env.validate_env_params ' ),
350+ patch ('node_cli.configs.user.validate_alias_or_address ' ),
346351 ):
347- result = run_command (restore_node , [backup_path , './tests/test-env' ])
352+ user_conf_path = request .getfixturevalue (test_user_conf ).as_posix ()
353+
354+ result = run_command (restore_node , [backup_path , user_conf_path ])
348355 assert result .exit_code == 0
349356 assert 'Node is restored from backup\n ' in result .output # noqa
357+ assert mock_restore_op .call_args [0 ][0 ].get ('BACKUP_RUN' ) == 'True'
350358
351- assert mock_restore_op .call_args [0 ][0 ].get ('BACKUP_RUN' ) == 'True'
352-
353-
354- def test_restore_no_snapshot (mocked_g_config ):
355- pathlib .Path (SKALE_DIR ).mkdir (parents = True , exist_ok = True )
356- result = run_command (backup_node , ['/tmp' ])
357- backup_path = result .output .replace ('Backup archive successfully created: ' , '' ).replace (
358- '\n ' , ''
359- )
360-
361- with (
362- patch ('node_cli.core.node.restore_op' , MagicMock ()) as mock_restore_op ,
363- patch ('subprocess.run' , new = subprocess_run_mock ),
364- patch ('node_cli.core.resources.get_disk_size' , return_value = BIG_DISK_SIZE ),
365- patch ('node_cli.utils.decorators.is_node_inited' , return_value = False ),
366- patch (
367- 'node_cli.core.node.CliMetaManager.get_meta_info' ,
368- return_value = CliMeta (version = '2.4.0' , config_stream = '3.0.2' ),
369- ),
370- patch ('node_cli.operations.base.configure_nftables' ),
371- patch ('node_cli.configs.env.validate_env_params' ),
372- ):
373- result = run_command (restore_node , [backup_path , './tests/test-env' , '--no-snapshot' ])
359+ result = run_command (restore_node , [backup_path , user_conf_path , '--no-snapshot' ])
374360 assert result .exit_code == 0
375361 assert 'Node is restored from backup\n ' in result .output # noqa
376-
377- assert mock_restore_op .call_args [0 ][0 ].get ('BACKUP_RUN' ) is None
362+ assert mock_restore_op .call_args [0 ][0 ].get ('BACKUP_RUN' ) is None
378363
379364
380365def test_maintenance_on ():
@@ -401,13 +386,15 @@ def test_maintenance_off(mocked_g_config):
401386 )
402387
403388
404- def test_turn_off_maintenance_on (mocked_g_config ):
389+ def test_turn_off_maintenance_on (mocked_g_config , regular_user_conf ):
405390 resp_mock = response_mock (requests .codes .ok , {'status' : 'ok' , 'payload' : None })
406391 with (
407392 mock .patch ('subprocess.run' , new = subprocess_run_mock ),
393+ mock .patch ('node_cli.core.node.INIT_ENV_FILEPATH' , regular_user_conf .as_posix ()),
408394 mock .patch ('node_cli.core.node.turn_off_op' ),
409395 mock .patch ('node_cli.utils.decorators.is_node_inited' , return_value = True ),
410- patch ('node_cli.configs.env.validate_env_params' ),
396+ mock .patch ('node_cli.configs.user.validate_alias_or_address' ),
397+ mock .patch ('node_cli.cli.node.TYPE' , NodeType .REGULAR )
411398 ):
412399 result = run_command_mock (
413400 'node_cli.utils.helper.requests.post' ,
@@ -431,21 +418,21 @@ def test_turn_off_maintenance_on(mocked_g_config):
431418 assert result .exit_code == CLIExitCodes .UNSAFE_UPDATE
432419
433420
434- def test_turn_on_maintenance_off (mocked_g_config ):
421+ def test_turn_on_maintenance_off (mocked_g_config , regular_user_conf ):
435422 resp_mock = response_mock (requests .codes .ok , {'status' : 'ok' , 'payload' : None })
436423 with (
437424 mock .patch ('subprocess.run' , new = subprocess_run_mock ),
438425 mock .patch ('node_cli.core.node.get_flask_secret_key' ),
439426 mock .patch ('node_cli.core.node.turn_on_op' ),
440427 mock .patch ('node_cli.core.node.is_base_containers_alive' ),
441428 mock .patch ('node_cli.utils.decorators.is_node_inited' , return_value = True ),
442- patch ('node_cli.configs.env.validate_env_params ' ),
429+ patch ('node_cli.configs.user.validate_alias_or_address ' ),
443430 ):
444431 result = run_command_mock (
445432 'node_cli.utils.helper.requests.post' ,
446433 resp_mock ,
447434 _turn_on ,
448- ['./tests/test-env' , '--maintenance-off' , '--sync-schains' , '--yes' ],
435+ [regular_user_conf . as_posix () , '--maintenance-off' , '--sync-schains' , '--yes' ],
449436 )
450437
451438 assert result .exit_code == 0
0 commit comments