File: test_passcommand.py

package info (click to toggle)
borgmatic 2.0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,752 kB
  • sloc: python: 58,506; sh: 150; makefile: 8; javascript: 5
file content (45 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flexmock import flexmock

from borgmatic.borg import passcommand as module


def test_run_passcommand_does_not_raise():
    module.run_passcommand.cache_clear()
    flexmock(module.borgmatic.execute).should_receive(
        'execute_command_and_capture_output',
    ).and_return('passphrase')

    assert module.run_passcommand('passcommand', working_directory=None) == 'passphrase'


def test_get_passphrase_from_passcommand_with_configured_passcommand_runs_it():
    module.run_passcommand.cache_clear()
    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
        '/working',
    )
    flexmock(module).should_receive('run_passcommand').with_args('command', '/working').and_return(
        'passphrase',
    ).once()

    assert (
        module.get_passphrase_from_passcommand(
            {'encryption_passcommand': 'command'},
        )
        == 'passphrase'
    )


def test_get_passphrase_from_passcommand_without_configured_passcommand_bails():
    flexmock(module).should_receive('run_passcommand').never()

    assert module.get_passphrase_from_passcommand({}) is None


def test_run_passcommand_caches_passcommand_after_first_call():
    module.run_passcommand.cache_clear()
    flexmock(module.borgmatic.execute).should_receive(
        'execute_command_and_capture_output',
    ).and_return('passphrase').once()

    assert module.run_passcommand('passcommand', working_directory=None) == 'passphrase'
    assert module.run_passcommand('passcommand', working_directory=None) == 'passphrase'