File: test_rename.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 (142 lines) | stat: -rw-r--r-- 3,950 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import logging

from borgmatic.borg import rename as module
from tests.unit.test_verbosity import insert_logging_mock


def test_make_rename_command_includes_log_info():
    insert_logging_mock(logging.INFO)

    command = module.make_rename_command(
        dry_run=False,
        repository_name='repo',
        old_archive_name='old_archive',
        new_archive_name='new_archive',
        config={},
        local_borg_version='1.2.3',
        local_path='borg',
        remote_path=None,
    )

    assert command == ('borg', 'rename', '--info', 'repo::old_archive', 'new_archive')


def test_make_rename_command_includes_log_debug():
    insert_logging_mock(logging.DEBUG)

    command = module.make_rename_command(
        dry_run=False,
        repository_name='repo',
        old_archive_name='old_archive',
        new_archive_name='new_archive',
        config={},
        local_borg_version='1.2.3',
        local_path='borg',
        remote_path=None,
    )

    assert command == ('borg', 'rename', '--debug', '--show-rc', 'repo::old_archive', 'new_archive')


def test_make_rename_command_includes_dry_run():
    command = module.make_rename_command(
        dry_run=True,
        repository_name='repo',
        old_archive_name='old_archive',
        new_archive_name='new_archive',
        config={},
        local_borg_version='1.2.3',
        local_path='borg',
        remote_path=None,
    )

    assert command == ('borg', 'rename', '--dry-run', 'repo::old_archive', 'new_archive')


def test_make_rename_command_includes_remote_path():
    command = module.make_rename_command(
        dry_run=False,
        repository_name='repo',
        old_archive_name='old_archive',
        new_archive_name='new_archive',
        config={},
        local_borg_version='1.2.3',
        local_path='borg',
        remote_path='borg1',
    )

    assert command == (
        'borg',
        'rename',
        '--remote-path',
        'borg1',
        'repo::old_archive',
        'new_archive',
    )


def test_make_rename_command_includes_umask():
    command = module.make_rename_command(
        dry_run=False,
        repository_name='repo',
        old_archive_name='old_archive',
        new_archive_name='new_archive',
        config={'umask': '077'},
        local_borg_version='1.2.3',
        local_path='borg',
        remote_path=None,
    )

    assert command == ('borg', 'rename', '--umask', '077', 'repo::old_archive', 'new_archive')


def test_make_rename_command_includes_log_json():
    command = module.make_rename_command(
        dry_run=False,
        repository_name='repo',
        old_archive_name='old_archive',
        new_archive_name='new_archive',
        config={'log_json': True},
        local_borg_version='1.2.3',
        local_path='borg',
        remote_path=None,
    )

    assert command == ('borg', 'rename', '--log-json', 'repo::old_archive', 'new_archive')


def test_make_rename_command_includes_lock_wait():
    command = module.make_rename_command(
        dry_run=False,
        repository_name='repo',
        old_archive_name='old_archive',
        new_archive_name='new_archive',
        config={'lock_wait': 5},
        local_borg_version='1.2.3',
        local_path='borg',
        remote_path=None,
    )

    assert command == ('borg', 'rename', '--lock-wait', '5', 'repo::old_archive', 'new_archive')


def test_make_rename_command_includes_extra_borg_options():
    command = module.make_rename_command(
        dry_run=False,
        repository_name='repo',
        old_archive_name='old_archive',
        new_archive_name='new_archive',
        config={'extra_borg_options': {'rename': '--extra "value with space"'}},
        local_borg_version='1.2.3',
        local_path='borg',
        remote_path=None,
    )

    assert command == (
        'borg',
        'rename',
        '--extra',
        'value with space',
        'repo::old_archive',
        'new_archive',
    )