Skip to content

Commit

Permalink
Fix DockerUtils wrong initialization in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
badrogger committed Oct 26, 2022
1 parent f0b5c50 commit 061d9b8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tests/routes/ssl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def post_bp_files_data(bp, request, file_data, full_response=False, **kwargs):
def test_upload(skale_bp, ssl_folder, db, cert_key_pair_host):
cert_path, key_path = cert_key_pair_host
with mock.patch('web.routes.ssl.set_schains_need_reload'), \
mock.patch('core.nginx.restart_nginx_container'):
mock.patch('web.routes.ssl.reload_nginx'):
with files_data(cert_path, key_path, force=False) as data:
response = post_bp_files_data(
skale_bp,
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_upload_bad_cert(skale_bp, db, ssl_folder, bad_cert_host):
def test_upload_cert_exist(skale_bp, db, cert_key_pair_host, cert_key_pair):
cert_path, key_path = cert_key_pair_host
with mock.patch('web.routes.ssl.set_schains_need_reload'), \
mock.patch('core.nginx.restart_nginx_container'):
mock.patch('web.routes.ssl.reload_nginx'):
with files_data(cert_path, key_path, force=False) as data:
response = post_bp_files_data(
skale_bp,
Expand Down
5 changes: 3 additions & 2 deletions tests/schains/checks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,15 @@ def test_blocks_check(schain_checks):
assert not schain_checks.blocks.status


def test_init_checks(skale, schain_db, uninited_rule_controller):
def test_init_checks(skale, schain_db, uninited_rule_controller, dutils):
schain_name = schain_db
schain_record = SChainRecord.get_by_name(schain_name)
checks = SChainChecks(
schain_name,
TEST_NODE_ID,
schain_record=schain_record,
rule_controller=uninited_rule_controller
rule_controller=uninited_rule_controller,
dutils=dutils
)
assert checks.name == schain_name
assert checks.node_id == TEST_NODE_ID
Expand Down
3 changes: 2 additions & 1 deletion tests/schains/monitor/base_monitor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def test_crashing_monitor(
node_config=node_config,
rotation_data={'rotation_id': 1, 'leaving_node': 1},
checks=schain_checks,
rule_controller=rule_controller
rule_controller=rule_controller,
dutils=dutils
)
with pytest.raises(Exception):
test_monitor.run()
Expand Down
12 changes: 10 additions & 2 deletions tests/schains/monitor/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ def skaled_container(self) -> CheckRes:


@pytest.fixture
def checks(schain_db, _schain_name, rule_controller, node_config, ima_data):
def checks(
schain_db,
_schain_name,
rule_controller,
node_config,
ima_data,
dutils
):
schain_record = upsert_schain_record(schain_db)
return SChainChecksMock(
_schain_name,
node_config.id,
schain_record,
rule_controller=rule_controller
rule_controller=rule_controller,
dutils=dutils
)


Expand Down
11 changes: 7 additions & 4 deletions tests/schains/runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_set_rotation(schain_config):
assert data['params'] == params


def test_is_exited():
def test_is_exited(dutils):
schain_name = 'schain_test'
info_mock = {
'status': 'exited',
Expand All @@ -36,9 +36,12 @@ def test_is_exited():
}
}
}
with mock.patch('core.schains.runner.DockerUtils.get_info',
new=mock.Mock(return_value=info_mock)):
assert is_exited(schain_name)
get_info = dutils.get_info
try:
dutils.get_info = mock.Mock(return_value=info_mock)
assert is_exited(schain_name, dutils=dutils)
finally:
dutils.get_info = get_info


def test_get_leaving_schains_for_node(skale, node_config): # TODO: improve test
Expand Down

0 comments on commit 061d9b8

Please sign in to comment.