-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathinit_test.py
64 lines (49 loc) · 2.46 KB
/
init_test.py
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
import unittest
from unittest import mock
import restic
from restic.internal import init
class InitTest(unittest.TestCase):
@mock.patch.object(init.command_executor, 'execute')
def test_init_with_no_parameters(self, mock_execute):
mock_execute.return_value = """
{"message_type":"initialized","id":"d0c84a66bffea61b4cbb88c39cea742127699b3f3af71127b68edcc142edff48","repository":"/tmp/tmp.lNaHYLGR7F"}
""".strip()
repository_id = restic.init()
self.assertEqual(
'd0c84a66bffea61b4cbb88c39cea742127699b3f3af71127b68edcc142edff48',
repository_id)
mock_execute.assert_called_with(['restic', '--json', 'init'])
# Prior to restic 0.15.0, restic responded with plaintext instead of JSON.
@mock.patch.object(init.command_executor, 'execute')
def test_init_legacy_format(self, mock_execute):
mock_execute.return_value = (
'created restic repository 054ed643d8 at /media/backup1')
repository_id = restic.init()
self.assertEqual('054ed643d8', repository_id)
mock_execute.assert_called_with(['restic', '--json', 'init'])
@mock.patch.object(init.command_executor, 'execute')
def test_init_with_secondary_repository(self, mock_execute):
mock_execute.return_value = """
{"message_type":"initialized","id":"d0c84a66bffea61b4cbb88c39cea742127699b3f3af71127b68edcc142edff48","repository":"/tmp/tmp.lNaHYLGR7F"}
""".strip()
repository_id = restic.init(
copy_chunker_params=True,
from_repo='s3:https://some.backend.com/mybucket')
self.assertEqual(
'd0c84a66bffea61b4cbb88c39cea742127699b3f3af71127b68edcc142edff48',
repository_id)
mock_execute.assert_called_with([
'restic', '--json', 'init', '--copy-chunker-params', '--from-repo',
's3:https://some.backend.com/mybucket'
])
@mock.patch.object(init.command_executor, 'execute')
def test_init_with_repository_version(self, mock_execute):
mock_execute.return_value = """
{"message_type":"initialized","id":"d0c84a66bffea61b4cbb88c39cea742127699b3f3af71127b68edcc142edff48","repository":"/tmp/tmp.lNaHYLGR7F"}
""".strip()
repository_id = restic.init(repository_version=1)
self.assertEqual(
'd0c84a66bffea61b4cbb88c39cea742127699b3f3af71127b68edcc142edff48',
repository_id)
mock_execute.assert_called_with(
['restic', '--json', 'init', '--repository-version', '1'])