Raise ValueError when snapshot name contains a '/'
This commit is contained in:
parent
41599058fe
commit
50c7d92f2a
@ -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
|
||||||
|
@ -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):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user