Browse Source

refactor tests

Divyansh Singh 2 years ago
parent
commit
16d7131fb7
2 changed files with 15 additions and 12 deletions
  1. 1 2
      borgmatic/commands/borgmatic.py
  2. 14 10
      tests/unit/commands/test_borgmatic.py

+ 1 - 2
borgmatic/commands/borgmatic.py

@@ -267,10 +267,9 @@ def run_actions(
         'repository': repository_path,
         'repository': repository_path,
         # Deprecated: For backwards compatibility with borgmatic < 1.6.0.
         # Deprecated: For backwards compatibility with borgmatic < 1.6.0.
         'repositories': ','.join([repo['path'] for repo in location['repositories']]),
         'repositories': ','.join([repo['path'] for repo in location['repositories']]),
+        'log_file': global_arguments.log_file if global_arguments.log_file else '',
     }
     }
 
 
-    hook_context['log_file'] = global_arguments.log_file if global_arguments.log_file else ''
-
     command.execute_hook(
     command.execute_hook(
         hooks.get('before_actions'),
         hooks.get('before_actions'),
         hooks.get('umask'),
         hooks.get('umask'),

+ 14 - 10
tests/unit/commands/test_borgmatic.py

@@ -422,25 +422,27 @@ def test_run_actions_runs_rcreate():
         )
         )
     )
     )
 
 
+
 def test_run_actions_adds_log_file_to_hook_context():
 def test_run_actions_adds_log_file_to_hook_context():
     flexmock(module).should_receive('add_custom_log_levels')
     flexmock(module).should_receive('add_custom_log_levels')
     flexmock(module.command).should_receive('execute_hook')
     flexmock(module.command).should_receive('execute_hook')
+    expected = flexmock()
     flexmock(borgmatic.actions.create).should_receive('run_create').with_args(
     flexmock(borgmatic.actions.create).should_receive('run_create').with_args(
-        config_filename=flexmock(),
+        config_filename=object,
         repository={'path': 'repo'},
         repository={'path': 'repo'},
         location={'repositories': []},
         location={'repositories': []},
-        storage=flexmock(),
+        storage=object,
         hooks={},
         hooks={},
-        hook_context={'log_file': 'foo'},
-        local_borg_version=flexmock(),
-        create_arguments=flexmock(),
-        global_arguments=flexmock(dry_run=False, log_file='foo'),
+        hook_context={'repository': 'repo', 'repositories': '', 'log_file': 'foo'},
+        local_borg_version=object,
+        create_arguments=object,
+        global_arguments=object,
         dry_run_label='',
         dry_run_label='',
-        local_path=flexmock(),
-        remote_path=flexmock(),
-    ).once()
+        local_path=object,
+        remote_path=object,
+    ).once().and_return(expected)
 
 
-    tuple(
+    result = tuple(
         module.run_actions(
         module.run_actions(
             arguments={'global': flexmock(dry_run=False, log_file='foo'), 'create': flexmock()},
             arguments={'global': flexmock(dry_run=False, log_file='foo'), 'create': flexmock()},
             config_filename=flexmock(),
             config_filename=flexmock(),
@@ -455,6 +457,8 @@ def test_run_actions_adds_log_file_to_hook_context():
             repository={'path': 'repo'},
             repository={'path': 'repo'},
         )
         )
     )
     )
+    assert result == (expected,)
+
 
 
 def test_run_actions_runs_transfer():
 def test_run_actions_runs_transfer():
     flexmock(module).should_receive('add_custom_log_levels')
     flexmock(module).should_receive('add_custom_log_levels')