Raise ValueError when snapshot name contains a '/'

This commit is contained in:
Eric Torres 2019-03-30 14:22:46 -07:00
parent 41599058fe
commit 50c7d92f2a
2 changed files with 11 additions and 3 deletions

View File

@ -146,7 +146,11 @@ class Repository(Hierarchy):
:param name: name of the Snapshot :param name: name of the Snapshot
:type name: str or path-like object :type name: str or path-like object
:rtype: path-like object :rtype: path-like object
:raises: ValueError if name contains slashes
""" """
if "/" in str(name):
raise ValueError("Names cannot contain slashes")
return self.snapshot_dir / name return self.snapshot_dir / name
@property @property

View File

@ -50,10 +50,14 @@ class TestRepositoryPreCreate(unittest.TestCase):
} }
repo = Repository("backup") repo = Repository("backup")
snapshot_path = repo.gen_snapshot_path(name)
self.assertEqual(snapshot_path, Path(f"backup/data/{name}")) if "/" not in name:
self.assertIsInstance(snapshot_path, Path) snapshot_path = repo.gen_snapshot_path(name)
self.assertEqual(snapshot_path, Path(f"backup/data/{name}"))
self.assertIsInstance(snapshot_path, Path)
else:
with self.assertRaises(ValueError):
snapshot_path = repo.gen_snapshot_path(name)
@given(lists(builds(Snapshot, text()), unique=True)) @given(lists(builds(Snapshot, text()), unique=True))
def test_empty(self, l): def test_empty(self, l):