borgapi 0.6.1__py3-none-any.whl → 0.7.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,136 +0,0 @@
1
- """Test create command"""
2
- import sys
3
- from io import BytesIO, TextIOWrapper
4
-
5
- from borg.archive import Archive
6
-
7
- from .test_01_borgapi import BorgapiTests
8
-
9
-
10
- class CreateTests(BorgapiTests):
11
- """Create command tests"""
12
-
13
- def test_01_basic(self):
14
- """Create new archive"""
15
- self.api.create(self.archive, self.data)
16
- output = self.api.list(self.repo, json=True)
17
- num_archives = len(output["archives"])
18
- self.assertEqual(num_archives, 1, "Archive not saved")
19
- archive_name = output["archives"][0]["name"]
20
- self.assertEqual(archive_name, "1", "Archive name does not match set name")
21
-
22
- def test_02_second(self):
23
- """Create second archive after data modification"""
24
- self.api.create(self.archive, self.data)
25
- with open(self.file_3, "w+") as fp:
26
- fp.write("New Data")
27
- self.api.create(f"{self.repo}::2", self.data)
28
-
29
- output = self.api.list(self.repo, json=True)
30
- num_archives = len(output["archives"])
31
- self.assertEqual(num_archives, 2, "Multiple archives not saved")
32
- archive_1_name = output["archives"][0]["name"]
33
- self.assertEqual(archive_1_name, "1", "Archive name does not match set name")
34
- archive_2_name = output["archives"][1]["name"]
35
- self.assertEqual(archive_2_name, "2", "Archive name does not match set name")
36
-
37
- def test_03_already_exists(self):
38
- """Create an archive with an existing name"""
39
- self.api.create(self.archive, self.data)
40
- self.assertRaises(
41
- Archive.AlreadyExists,
42
- self.api.create,
43
- self.archive,
44
- self.data,
45
- )
46
-
47
- def test_04_stdin(self):
48
- """Read input from stdin and save to archvie"""
49
- temp_stdin = TextIOWrapper(BytesIO(bytes(self.file_3_text, "utf-8")))
50
- sys.stdin = temp_stdin
51
- name = "file_3_stdin.txt"
52
- mode = "0777" # "-rwxrwxrwx"
53
-
54
- try:
55
- self.api.create(
56
- self.archive,
57
- "-",
58
- stdin_name=name,
59
- stdin_mode=mode,
60
- )
61
- finally:
62
- temp_stdin.close()
63
- sys.stdin = sys.__stdin__
64
-
65
- output = self.api.list(self.archive, json_lines=True)
66
- self.assertEqual(output["path"], name, "Unexpected file name")
67
- self.assertEqual(output["mode"], "-rwxrwxrwx", "Unexpected file mode")
68
-
69
- def test_04_output_string(self):
70
- """Create string info"""
71
- output = self.api.create(self.archive, self.data, stats=True, list=True)
72
- self._display("create string info", output, False)
73
- self.assertType(output["stats"], str)
74
- self.assertType(output["list"], str)
75
-
76
- def test_05_output_json(self):
77
- """Create json info"""
78
- output = self.api.create(
79
- self.archive,
80
- self.data,
81
- json=True,
82
- log_json=True,
83
- list=True,
84
- )
85
- self._display("create string info", output, False)
86
- self.assertType(output["stats"], dict)
87
- self.assertAnyType(output["list"], list, dict)
88
-
89
- def test_06_output_mixed_1(self):
90
- """Create mixed output (stats json, list string)"""
91
- output = self.api.create(self.archive, self.data, json=True, list=True)
92
- self._display("create mixed output (stats json, list string)", output, False)
93
- self.assertType(output["stats"], dict)
94
- self.assertType(output["list"], str)
95
-
96
- def test_07_output_mixed_2(self):
97
- """Create mixed output (stats string, list json)"""
98
- output = self.api.create(
99
- self.archive,
100
- self.data,
101
- stats=True,
102
- log_json=True,
103
- list=True,
104
- )
105
- self._display("create mixed output (stats string, list json)", output, False)
106
- self.assertType(output["stats"], str)
107
- self.assertAnyType(output["list"], list, dict)
108
-
109
- def test_08_list_string(self):
110
- """Create list string"""
111
- output = self.api.create(self.archive, self.data, list=True)
112
- self._display("create list string", output)
113
- self.assertType(output, str)
114
-
115
- def test_09_stats_json(self):
116
- """Create stats json"""
117
- output = self.api.create(self.archive, self.data, json=True)
118
- self._display("create stats json", output)
119
- self.assertType(output, dict)
120
-
121
- def test_10_list_json(self):
122
- """Create list json"""
123
- output = self.api.create(
124
- self.archive,
125
- self.data,
126
- log_json=True,
127
- list=True,
128
- )
129
- self._display("create list json", output)
130
- self.assertAnyType(output, list, dict)
131
-
132
- def test_11_stats_string(self):
133
- """Create stats string"""
134
- output = self.api.create(self.archive, self.data, stats=True)
135
- self._display("create stats string", output)
136
- self.assertType(output, str)
@@ -1,52 +0,0 @@
1
- """Test extract command"""
2
- from os import remove
3
-
4
- from .test_01_borgapi import BorgapiTests
5
-
6
-
7
- class ExtractTests(BorgapiTests):
8
- """Extract command tests"""
9
-
10
- def setUp(self):
11
- super().setUp()
12
- self._create_default()
13
-
14
- def test_01_basic(self):
15
- """Extract file"""
16
- remove(self.file_1)
17
- self.assertFileNotExists(self.file_1)
18
-
19
- self.api.extract(self.archive, self.file_1)
20
- self.assertFileExists(self.file_1)
21
-
22
- def test_02_not_exist(self):
23
- """Extract path that does not exist"""
24
- with self.assertLogs("borg", "WARNING") as logger:
25
- self.api.extract(self.archive, self.file_3)
26
- message = logger.records[0].getMessage()
27
- self.assertRegex(
28
- message,
29
- r".*?file_3.*never",
30
- "Warning not logged for bad path",
31
- )
32
-
33
- def test_03_stdout(self):
34
- """Capture Extracted File"""
35
- output = self.api.extract(self.archive, self.file_1, stdout=True)
36
- self.assertEqual(
37
- output,
38
- bytes(self.file_1_text, "utf-8"),
39
- "Extracted file text does not match",
40
- )
41
-
42
- def test_04_output_string(self):
43
- """list to log"""
44
- output = self.api.extract(self.archive, list=True, dry_run=True)
45
- self._display("extract 1", output)
46
- self.assertType(output, str)
47
-
48
- def test_05_output_json(self):
49
- """list to json"""
50
- output = self.api.extract(self.archive, log_json=True, list=True, dry_run=True)
51
- self._display("extract 2", output)
52
- self.assertAnyType(output, list, dict)
@@ -1,32 +0,0 @@
1
- """Test rename command"""
2
- from borg.archive import Archive
3
-
4
- from .test_01_borgapi import BorgapiTests
5
-
6
-
7
- class RenameTests(BorgapiTests):
8
- """Rename command tests"""
9
-
10
- def setUp(self):
11
- super().setUp()
12
- self._create_default()
13
-
14
- def test_01_basic(self):
15
- """Rename a archive"""
16
- output = self.api.list(self.repo, json=True)
17
- original_name = output["archives"][0]["name"]
18
- self.api.rename(self.archive, "2")
19
- output = self.api.list(self.repo, json=True)
20
- new_name = output["archives"][0]["name"]
21
- self.assertNotEqual(new_name, original_name, "Name change did not occur")
22
- self.assertEqual(new_name, "2", "Name did not change to expected output")
23
-
24
- def test_02_no_exist(self):
25
- """Rename nonexistant archive"""
26
- self.assertRaises(
27
- Archive.DoesNotExist,
28
- self.api.rename,
29
- f"{self.repo}::2",
30
- "3",
31
- msg="Renamed archive that does not exist",
32
- )
@@ -1,59 +0,0 @@
1
- """Test list command"""
2
- from .test_01_borgapi import BorgapiTests
3
-
4
-
5
- class ListTests(BorgapiTests):
6
- """List command tests"""
7
-
8
- def setUp(self):
9
- super().setUp()
10
- self._create_default()
11
-
12
- def test_01_basic(self):
13
- """List repo archvies and archive files"""
14
- output = self.api.list(self.repo, json=True)
15
- num_archvies = len(output["archives"])
16
- self.assertEqual(num_archvies, 1, "Unexpected number of archives returned")
17
-
18
- output = self.api.list(self.archive, json_lines=True)
19
- num_files = len(output)
20
- self.assertEqual(num_files, 3, "Unexpected number of files returned")
21
-
22
- def test_02_repo_basic(self):
23
- """List repo"""
24
- output = self.api.list(self.repo)
25
- self._display("list repo", output)
26
- self.assertType(output, str)
27
-
28
- def test_03_repo_short(self):
29
- """List repo short"""
30
- output = self.api.list(self.repo, short=True)
31
- self._display("list repo short", output)
32
- self.assertType(output, str)
33
-
34
- def test_04_repo_json(self):
35
- """List repo json"""
36
- output = self.api.list(self.repo, json=True)
37
- self._display("list repo json", output)
38
- self.assertAnyType(output, list, dict)
39
- output = self.api.list(self.repo, log_json=True)
40
- self._display("list repo log json", output)
41
- self.assertAnyType(output, str)
42
-
43
- def test_05_archive_basic(self):
44
- """List archive"""
45
- output = self.api.list(self.archive)
46
- self._display("list archive", output)
47
- self.assertType(output, str)
48
-
49
- def test_06_archive_short(self):
50
- """List archive short"""
51
- output = self.api.list(self.archive, short=True)
52
- self._display("list archive short", output)
53
- self.assertType(output, str)
54
-
55
- def test_07_archive_json(self):
56
- """List archive json"""
57
- output = self.api.list(self.archive, json_lines=True)
58
- self._display("list archive json", output)
59
- self.assertAnyType(output, list, dict)
@@ -1,54 +0,0 @@
1
- """Test deff command"""
2
- from .test_01_borgapi import BorgapiTests
3
-
4
-
5
- class DiffTests(BorgapiTests):
6
- """Diff command tests"""
7
-
8
- def setUp(self):
9
- super().setUp()
10
- self._create_default()
11
-
12
- def test_01_add_file(self):
13
- """Diff new file"""
14
- with open(self.file_3, "w") as fp:
15
- fp.write(self.file_3_text)
16
- self.api.create(f"{self.repo}::2", self.data)
17
- output = self.api.diff(self.archive, "2", json_lines=True)
18
- self.assertType(output, dict)
19
- modify_path = output["path"]
20
- modify_type = output["changes"][0]["type"]
21
- self.assertEqual(modify_path, self.file_3, "Unexpected new filename")
22
- self.assertEqual(modify_type, "added", "New file not listed as added")
23
-
24
- def test_02_modify_file(self):
25
- """Diff modified file"""
26
- with open(self.file_3, "w") as fp:
27
- fp.write(self.file_3_text)
28
- with open(self.file_2, "w") as fp:
29
- fp.write(self.file_3_text)
30
- self.api.create(f"{self.repo}::2", self.data)
31
- output = self.api.diff(self.archive, "2", json_lines=True, sort=True)
32
- self.assertType(output, list)
33
- modify_path = output[0]["path"]
34
- modify_type = output[0]["changes"][0]["type"]
35
- self.assertEqual(modify_path, self.file_2, "Unexpected file changed")
36
- self.assertEqual(modify_type, "modified", "Unexpected change type")
37
-
38
- def test_03_output(self):
39
- """Diff string"""
40
- with open(self.file_3, "w") as fp:
41
- fp.write(self.file_3_text)
42
- self.api.create(f"{self.repo}::2", self.data)
43
- output = self.api.diff(self.archive, "2")
44
- self._display("diff sting", output)
45
- self.assertType(output, str)
46
-
47
- def test_04_output_json(self):
48
- """Diff json"""
49
- with open(self.file_3, "w") as fp:
50
- fp.write(self.file_3_text)
51
- self.api.create(f"{self.repo}::2", self.data)
52
- output = self.api.diff(self.archive, "2", log_json=True)
53
- self._display("diff log json", output)
54
- self.assertAnyType(output, str)
@@ -1,68 +0,0 @@
1
- """Test delete command"""
2
- from borg.archive import Archive
3
- from borg.repository import Repository
4
-
5
- from .test_01_borgapi import BorgapiTests
6
-
7
-
8
- class DeleteTests(BorgapiTests):
9
- """Delete command tests"""
10
-
11
- def test_01_repository(self):
12
- """Delete repository"""
13
- self._create_default()
14
- self.api.delete(self.repo)
15
- self.assertRaises(
16
- Repository.DoesNotExist,
17
- self.api.list,
18
- self.repo,
19
- msg="Deleted repository still exists",
20
- )
21
-
22
- # pylint: disable=invalid-name
23
- def test_02_repository_not_exist(self):
24
- """Delete repository that doesn't exist"""
25
- self._make_clean(self.repo)
26
- self.assertRaises(
27
- Repository.InvalidRepository,
28
- self.api.delete,
29
- self.repo,
30
- msg="Deleted nonexistant repository",
31
- )
32
-
33
- def test_03_archive(self):
34
- """Delete archive"""
35
- self._create_default()
36
- self.api.delete(self.archive)
37
- self.assertRaises(
38
- Archive.DoesNotExist,
39
- self.api.list,
40
- self.archive,
41
- msg="Deleted archive still exists",
42
- )
43
-
44
- def test_04_archive_not_exist(self):
45
- """Delete archvie that doesn't exist"""
46
- with self.assertLogs("borg", "WARNING") as logger:
47
- self.api.delete(self.archive)
48
-
49
- message = logger.records[0].getMessage()
50
- self.assertRegex(
51
- message,
52
- r".*?1.*not found",
53
- "Warning not logged for bad archive name",
54
- )
55
-
56
- def test_05_stats_string(self):
57
- """Archvie stats string"""
58
- self._create_default()
59
- output = self.api.delete(self.archive, stats=True)
60
- self._display("delete 1", output)
61
- self.assertType(output, str)
62
-
63
- def test_06_stats_json(self):
64
- """Archvie stats json"""
65
- self._create_default()
66
- output = self.api.delete(self.archive, stats=True, log_json=True)
67
- self._display("delete 2", output)
68
- self.assertType(output, list, dict)
@@ -1,48 +0,0 @@
1
- """Test prune command"""
2
- from os import remove
3
- from time import sleep
4
-
5
- from .test_01_borgapi import BorgapiTests
6
-
7
-
8
- class PruneTests(BorgapiTests):
9
- """Prune command tests"""
10
-
11
- def setUp(self):
12
- super().setUp()
13
- self._create_default()
14
- sleep(1)
15
- with open(self.file_3, "w") as fp:
16
- fp.write(self.file_3_text)
17
- self.api.create(f"{self.repo}::2", self.data)
18
- sleep(1)
19
- remove(self.file_1)
20
- self.api.create(f"{self.repo}::3", self.data)
21
- sleep(1)
22
- with open(self.file_2, "w") as fp:
23
- fp.write(self.file_1_text)
24
- self.api.create(f"{self.repo}::4", self.data)
25
- sleep(1)
26
- remove(self.file_2)
27
- self.api.create(f"{self.repo}::5", self.data)
28
- sleep(1)
29
-
30
- # pylint: disable=invalid-sequence-index
31
- def test_01_basic(self):
32
- """Prune archives"""
33
- self.api.prune(self.repo, keep_last="3")
34
- output = self.api.list(self.repo, json=True)
35
- num_archives = len(output["archives"])
36
- self.assertEqual(num_archives, 3, "Unexpected number of archvies pruned")
37
-
38
- def test_02_output_list(self):
39
- """Prune output list"""
40
- output = self.api.prune(self.repo, keep_last="3", dry_run=True, list=True)
41
- self._display("prune list", output)
42
- self.assertType(output, str)
43
-
44
- def test_03_output_stats(self):
45
- """Prune output stats"""
46
- output = self.api.prune(self.repo, keep_last="3", dry_run=True, stats=True)
47
- self._display("prune stats", output)
48
- self.assertType(output, str)
@@ -1,50 +0,0 @@
1
- """Test info command"""
2
- from .test_01_borgapi import BorgapiTests
3
-
4
-
5
- class InfoTests(BorgapiTests):
6
- """Info command tests"""
7
-
8
- def setUp(self):
9
- super().setUp()
10
- self._create_default()
11
-
12
- def test_01_repository(self):
13
- """Repository info"""
14
- output = self.api.info(self.repo, json=True)
15
- self.assertKeyExists("cache", output)
16
- self.assertKeyNotExists("archives", output)
17
-
18
- def test_02_archive(self):
19
- """Archive info"""
20
- output = self.api.info(self.archive, json=True)
21
- self.assertKeyExists("cache", output)
22
- self.assertKeyExists("archives", output)
23
-
24
- def test_03_repo_string(self):
25
- """Repo output string"""
26
- output = self.api.info(self.repo)
27
- self._display("info repo string", output)
28
- self.assertType(output, str)
29
-
30
- def test_04_repo_json(self):
31
- """Repo output json"""
32
- output = self.api.info(self.repo, json=True)
33
- self._display("info repo json", output)
34
- self.assertAnyType(output, list, dict)
35
-
36
- output = self.api.info(self.repo, log_json=True)
37
- self._display("info repo log json", output)
38
- self.assertType(output, str)
39
-
40
- def test_05_archive_string(self):
41
- """Archive output string"""
42
- output = self.api.info(self.archive)
43
- self._display("info archive string", output)
44
- self.assertType(output, str)
45
-
46
- def test_06_archive_json(self):
47
- """Archive output json"""
48
- output = self.api.info(self.archive, json=True)
49
- self._display("info archive json", output)
50
- self.assertAnyType(output, list, dict)
@@ -1,50 +0,0 @@
1
- """Test mount and unmount commands"""
2
- from os import getenv
3
- from os.path import join
4
- from shutil import rmtree
5
- from time import sleep
6
-
7
- from .test_01_borgapi import BorgapiTests
8
-
9
-
10
- class MountTests(BorgapiTests):
11
- """Mount and Unmount command tests"""
12
-
13
- @classmethod
14
- def setUpClass(cls):
15
- super().setUpClass()
16
- cls.mountpoint = join(cls.temp, "mount")
17
- cls.repo_file = join(cls.mountpoint, "1", cls.file_1)
18
- cls.archive_file = join(cls.mountpoint, cls.file_1)
19
-
20
- def setUp(self):
21
- if getenv("BORGAPI_TEST_MOUNT_SKIP"):
22
- self.skipTest("llfuse not setup")
23
- super().setUp()
24
- self._create_default()
25
- self._make_clean(self.mountpoint)
26
-
27
- def tearDown(self):
28
- if not getenv("BORGAPI_TEST_KEEP_TEMP"):
29
- rmtree(self.mountpoint)
30
- super().tearDown()
31
-
32
- def test_01_repository(self):
33
- """Mount and unmount a repository"""
34
- output = self.api.mount(self.repo, self.mountpoint)
35
- sleep(5)
36
- self.assertTrue(output["pid"] != 0)
37
- self.assertFileExists(self.repo_file)
38
- self.api.umount(self.mountpoint)
39
- self.assertFileNotExists(self.repo_file)
40
- sleep(3)
41
-
42
- def test_02_archive(self):
43
- """Mount and unmount a archive"""
44
- output = self.api.mount(self.archive, self.mountpoint)
45
- sleep(5)
46
- self.assertTrue(output["pid"] != 0)
47
- self.assertFileExists(self.archive_file)
48
- self.api.umount(self.mountpoint)
49
- self.assertFileNotExists(self.archive_file)
50
- sleep(3)
@@ -1,81 +0,0 @@
1
- """Test key commands"""
2
- from os.path import join
3
- from shutil import rmtree
4
-
5
- from .test_01_borgapi import BorgapiTests
6
-
7
-
8
- class KeyTests(BorgapiTests):
9
- """Key command tests"""
10
-
11
- @classmethod
12
- def setUpClass(cls):
13
- super().setUpClass()
14
- cls.export_dir = join(cls.temp, "export")
15
- cls.key_file = join(cls.export_dir, "key.txt")
16
-
17
- def setUp(self):
18
- """Setup export / import tests"""
19
- super().setUp()
20
- self._make_clean(self.export_dir)
21
- self._create_default()
22
-
23
- def tearDown(self):
24
- """Tear down export / import tests"""
25
- rmtree(self.export_dir)
26
- super().tearDown()
27
-
28
- def test_01_change_passphrase(self):
29
- """Change key passphrase"""
30
- repo_config_file = join(self.repo, "config")
31
- repo_config = self._read_config(filename=repo_config_file)
32
-
33
- original_value = repo_config["repository"]["key"]
34
-
35
- self.api.set_environ(dictionary={"BORG_NEW_PASSPHRASE": "newpass"})
36
- self.api.key_change_passphrase(self.repo)
37
- self.api.unset_environ("BORG_NEW_PASSPHRASE")
38
-
39
- repo_config = self._read_config(filename=repo_config_file)
40
- key_change_value = repo_config["repository"]["key"]
41
-
42
- self.assertNotEqual(
43
- key_change_value,
44
- original_value,
45
- "Changed key matches original",
46
- )
47
-
48
- def test_02_export(self):
49
- """Export repo excryption key"""
50
- self.api.key_export(self.repo, self.key_file)
51
- self.assertFileExists(
52
- self.key_file,
53
- "Repo key not exported to expected location",
54
- )
55
-
56
- def test_03_export_paper(self):
57
- """Export repo excryption key"""
58
- self.api.key_export(self.repo, self.key_file, paper=True)
59
- self.assertFileExists(
60
- self.key_file,
61
- "Repo key not exported to expected location",
62
- )
63
-
64
- def test_04_import(self):
65
- """Import original key to repository"""
66
- self.api.key_export(self.repo, self.key_file)
67
-
68
- repo_config_file = join(self.repo, "config")
69
- repo_config = self._read_config(filename=repo_config_file)
70
- original_value = repo_config["repository"]["key"]
71
-
72
- self.api.key_import(self.repo, self.key_file)
73
-
74
- repo_config = self._read_config(filename=repo_config_file)
75
- restored_value = repo_config["repository"]["key"]
76
-
77
- self.assertEqual(
78
- restored_value,
79
- original_value,
80
- "Restored key does not match original",
81
- )
@@ -1,38 +0,0 @@
1
- """Test export tar command"""
2
- from os.path import join
3
- from shutil import rmtree
4
-
5
- from .test_01_borgapi import BorgapiTests
6
-
7
-
8
- class ExportTarTests(BorgapiTests):
9
- """Export Tar command tests"""
10
-
11
- def setUp(self):
12
- super().setUp()
13
- self._create_default()
14
-
15
- self.export_dir = join(self.temp, "export")
16
- self._make_clean(self.export_dir)
17
- self.tar_file = join(self.export_dir, "export.tar")
18
-
19
- def tearDown(self):
20
- rmtree(self.export_dir)
21
- super().tearDown()
22
-
23
- def test_01_basic(self):
24
- """Export tar file"""
25
- self.api.export_tar(self.archive, self.tar_file)
26
- self.assertFileExists(self.tar_file, "Tar file not exported")
27
-
28
- def test_02_stdout(self):
29
- """Export tar stdout"""
30
- output = self.api.export_tar(self.archive, "-")
31
- self._display("export tar 2", output)
32
- self.assertType(output, bytes)
33
-
34
- def test_03_output_json(self):
35
- """Export tar output"""
36
- output = self.api.export_tar(self.archive, self.tar_file, list=True)
37
- self._display("export tar 1", output)
38
- self.assertType(output, str)