From 3e2241461331283d4332d08675611c6294288532 Mon Sep 17 00:00:00 2001 From: Nain Date: Thu, 16 Mar 2023 14:01:29 -0400 Subject: [PATCH] Update tests Make them more explicit. Also formatting. --- tests/unit/actions/test_check.py | 27 +++++++++++++++++---------- tests/unit/actions/test_compact.py | 19 +++++++++++-------- tests/unit/actions/test_create.py | 5 +++-- tests/unit/actions/test_prune.py | 15 +++++++++------ 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/tests/unit/actions/test_check.py b/tests/unit/actions/test_check.py index db031403..bd0cf1c7 100644 --- a/tests/unit/actions/test_check.py +++ b/tests/unit/actions/test_check.py @@ -8,10 +8,11 @@ def test_run_check_calls_hooks_for_configured_repository(): flexmock(module.borgmatic.config.checks).should_receive( 'repository_enabled_for_checks' ).and_return(True) - flexmock(module.borgmatic.borg.check).should_receive('check_archives') + flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.check).should_receive('check_archives').once() flexmock(module.borgmatic.hooks.command).should_receive('execute_hook').times(2) check_arguments = flexmock( - repository=None, progress=flexmock(), repair=flexmock(), only=flexmock(), force=flexmock() + repository=None, progress=flexmock(), repair=flexmock(), only=flexmock(), force=flexmock(), ) global_arguments = flexmock(monitoring_verbosity=1, dry_run=False) @@ -33,16 +34,22 @@ def test_run_check_calls_hooks_for_configured_repository(): def test_run_check_runs_with_select_repository(): flexmock(module.logger).answer = lambda message: None - flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True) - flexmock(module.borgmatic.borg.check).should_receive('check_archives') + flexmock(module.borgmatic.config.validate).should_receive( + 'repositories_match' + ).once().and_return(True) + flexmock(module.borgmatic.borg.check).should_receive('check_archives').once() check_arguments = flexmock( - repository='repo', progress=flexmock(), repair=flexmock(), only=flexmock(), force=flexmock() + repository=flexmock(), + progress=flexmock(), + repair=flexmock(), + only=flexmock(), + force=flexmock(), ) global_arguments = flexmock(monitoring_verbosity=1, dry_run=False) module.run_check( config_filename='test.yaml', - repository='repo', + repository=flexmock(), location={'repositories': ['repo']}, storage={}, consistency={}, @@ -58,12 +65,12 @@ def test_run_check_runs_with_select_repository(): def test_run_check_bails_if_repository_does_not_match(): flexmock(module.logger).answer = lambda message: None - flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return( - False - ) + flexmock(module.borgmatic.config.validate).should_receive( + 'repositories_match' + ).once().and_return(False) flexmock(module.borgmatic.borg.check).should_receive('check_archives').never() check_arguments = flexmock( - repository='repo2', + repository=flexmock(), progress=flexmock(), repair=flexmock(), only=flexmock(), diff --git a/tests/unit/actions/test_compact.py b/tests/unit/actions/test_compact.py index fab21f32..97f3d5b7 100644 --- a/tests/unit/actions/test_compact.py +++ b/tests/unit/actions/test_compact.py @@ -6,7 +6,8 @@ from borgmatic.actions import compact as module def test_compact_actions_calls_hooks_for_configured_repository(): flexmock(module.logger).answer = lambda message: None flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True) - flexmock(module.borgmatic.borg.compact).should_receive('compact_segments') + flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.compact).should_receive('compact_segments').once() flexmock(module.borgmatic.hooks.command).should_receive('execute_hook').times(2) compact_arguments = flexmock( repository=None, progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock() @@ -31,11 +32,13 @@ def test_compact_actions_calls_hooks_for_configured_repository(): def test_compact_runs_with_select_repository(): flexmock(module.logger).answer = lambda message: None - flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True) + flexmock(module.borgmatic.config.validate).should_receive( + 'repositories_match' + ).once().and_return(True) flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True) - flexmock(module.borgmatic.borg.compact).should_receive('compact_segments') + flexmock(module.borgmatic.borg.compact).should_receive('compact_segments').once() compact_arguments = flexmock( - repository='repo', progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock() + repository=flexmock(), progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock() ) global_arguments = flexmock(monitoring_verbosity=1, dry_run=False) @@ -58,12 +61,12 @@ def test_compact_runs_with_select_repository(): def test_compact_bails_if_repository_does_not_match(): flexmock(module.logger).answer = lambda message: None flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True) - flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return( - False - ) + flexmock(module.borgmatic.config.validate).should_receive( + 'repositories_match' + ).once().and_return(False) flexmock(module.borgmatic.borg.compact).should_receive('compact_segments').never() compact_arguments = flexmock( - repository='repo2', progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock() + repository=flexmock(), progress=flexmock(), cleanup_commits=flexmock(), threshold=flexmock() ) global_arguments = flexmock(monitoring_verbosity=1, dry_run=False) diff --git a/tests/unit/actions/test_create.py b/tests/unit/actions/test_create.py index 04d7abc0..6eb18c2c 100644 --- a/tests/unit/actions/test_create.py +++ b/tests/unit/actions/test_create.py @@ -3,8 +3,9 @@ from flexmock import flexmock from borgmatic.actions import create as module -def test_run_create_executes_and_calls_hooks(): +def test_run_create_executes_and_calls_hooks_for_configured_repository(): flexmock(module.logger).answer = lambda message: None + flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() flexmock(module.borgmatic.borg.create).should_receive('create_archive').once() flexmock(module.borgmatic.hooks.command).should_receive('execute_hook').times(2) flexmock(module.borgmatic.hooks.dispatch).should_receive('call_hooks').and_return({}) @@ -12,7 +13,7 @@ def test_run_create_executes_and_calls_hooks(): 'call_hooks_even_if_unconfigured' ).and_return({}) create_arguments = flexmock( - repository=flexmock(), + repository=None, progress=flexmock(), stats=flexmock(), json=flexmock(), diff --git a/tests/unit/actions/test_prune.py b/tests/unit/actions/test_prune.py index 6c09e0c9..b9119898 100644 --- a/tests/unit/actions/test_prune.py +++ b/tests/unit/actions/test_prune.py @@ -5,7 +5,8 @@ from borgmatic.actions import prune as module def test_run_prune_calls_hooks_of_configured_repository(): flexmock(module.logger).answer = lambda message: None - flexmock(module.borgmatic.borg.prune).should_receive('prune_archives') + flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never() + flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').once() flexmock(module.borgmatic.hooks.command).should_receive('execute_hook').times(2) prune_arguments = flexmock(repository=None, stats=flexmock(), list_archives=flexmock()) global_arguments = flexmock(monitoring_verbosity=1, dry_run=False) @@ -28,8 +29,10 @@ def test_run_prune_calls_hooks_of_configured_repository(): def test_run_prune_runs_with_select_repository(): flexmock(module.logger).answer = lambda message: None - flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True) - flexmock(module.borgmatic.borg.prune).should_receive('prune_archives') + flexmock(module.borgmatic.config.validate).should_receive( + 'repositories_match' + ).once().and_return(True) + flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').once() prune_arguments = flexmock(repository=flexmock(), stats=flexmock(), list_archives=flexmock()) global_arguments = flexmock(monitoring_verbosity=1, dry_run=False) @@ -51,9 +54,9 @@ def test_run_prune_runs_with_select_repository(): def test_run_prune_bails_if_repository_does_not_match(): flexmock(module.logger).answer = lambda message: None - flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return( - False - ) + flexmock(module.borgmatic.config.validate).should_receive( + 'repositories_match' + ).once().and_return(False) flexmock(module.borgmatic.borg.prune).should_receive('prune_archives').never() prune_arguments = flexmock(repository=flexmock(), stats=flexmock(), list_archives=flexmock()) global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)