Change test repository directory

This commit is contained in:
Eric Torres 2019-04-16 17:14:46 -07:00
parent e7a8719dc9
commit 43d4a07d26

View File

@ -63,7 +63,7 @@ class TestRepositoryPreCreate(unittest.TestCase):
@given(lists(from_regex(VALID_SNAPSHOT_NAME, fullmatch=True), unique=True)) @given(lists(from_regex(VALID_SNAPSHOT_NAME, fullmatch=True), unique=True))
def test_empty(self, snapshots): def test_empty(self, snapshots):
self.mocked_r_metadata.return_value = snapshots.copy() self.mocked_r_metadata.return_value = snapshots.copy()
repo = Repository("backup") repo = Repository("/tmp/backup")
if not snapshots: if not snapshots:
self.assertTrue(repo.empty) self.assertTrue(repo.empty)
@ -73,14 +73,14 @@ class TestRepositoryPreCreate(unittest.TestCase):
@given(lists(from_regex(VALID_SNAPSHOT_NAME, fullmatch=True), unique=True)) @given(lists(from_regex(VALID_SNAPSHOT_NAME, fullmatch=True), unique=True))
def test_dunder_len(self, snapshots): def test_dunder_len(self, snapshots):
self.mocked_r_metadata.return_value = snapshots.copy() self.mocked_r_metadata.return_value = snapshots.copy()
repo = Repository("backup") repo = Repository("/tmp/backup")
self.assertEqual(len(repo.snapshots), len(snapshots)) self.assertEqual(len(repo.snapshots), len(snapshots))
@given(text(min_size=1)) @given(text(min_size=1))
def test_dunder_contains(self, name): def test_dunder_contains(self, name):
self.mocked_r_metadata.return_value = [] self.mocked_r_metadata.return_value = []
repo = Repository("backup") repo = Repository("/tmp/backup")
self.assertFalse(name in repo) self.assertFalse(name in repo)
@ -94,7 +94,7 @@ class TestRepositoryPreCreate(unittest.TestCase):
self.assertTrue(Repository.is_valid_snapshot_name(name)) self.assertTrue(Repository.is_valid_snapshot_name(name))
def test_snapshots_returns_empty_list(self): def test_snapshots_returns_empty_list(self):
repo = Repository("backup") repo = Repository("/tmp/backup")
self.assertListEqual(repo.snapshots, []) self.assertListEqual(repo.snapshots, [])
@given( @given(
@ -102,7 +102,7 @@ class TestRepositoryPreCreate(unittest.TestCase):
) )
def snapshots_property_contains_snapshot_objects(self, snapshots): def snapshots_property_contains_snapshot_objects(self, snapshots):
self.mocked_r_metadata.return_value = snapshots self.mocked_r_metadata.return_value = snapshots
repo = Repository("backup") repo = Repository("/tmp/backup")
self.assertTrue(all(isinstance(p, Snapshot) for p in repo)) self.assertTrue(all(isinstance(p, Snapshot) for p in repo))
@ -153,7 +153,7 @@ class TestRepositoryPostCreate(unittest.TestCase):
@given(lists(from_regex(VALID_SNAPSHOT_NAME, fullmatch=True), unique=True)) @given(lists(from_regex(VALID_SNAPSHOT_NAME, fullmatch=True), unique=True))
def test_dunder_len(self, snapshots): def test_dunder_len(self, snapshots):
self.mocked_r_metadata.return_value = snapshots.copy() self.mocked_r_metadata.return_value = snapshots.copy()
repo = Repository("backup") repo = Repository("/tmp/backup")
repo.create_snapshot() repo.create_snapshot()
@ -163,14 +163,14 @@ class TestRepositoryPostCreate(unittest.TestCase):
@given(from_regex(VALID_SNAPSHOT_NAME, fullmatch=True)) @given(from_regex(VALID_SNAPSHOT_NAME, fullmatch=True))
def test_dunder_contains(self, name): def test_dunder_contains(self, name):
self.mocked_path.return_value.exists.return_value = False self.mocked_path.return_value.exists.return_value = False
repo = Repository("backup") repo = Repository("/tmp/backup")
repo.create_snapshot(name) repo.create_snapshot(name)
self.assertTrue(name in repo) self.assertTrue(name in repo)
def test_empty(self): def test_empty(self):
self.mocked_r_metadata.return_value = [] self.mocked_r_metadata.return_value = []
repo = Repository("backup") repo = Repository("/tmp/backup")
repo.create_snapshot() repo.create_snapshot()
@ -178,14 +178,14 @@ class TestRepositoryPostCreate(unittest.TestCase):
def test_snapshot_returns_snapshot_object(self): def test_snapshot_returns_snapshot_object(self):
self.mocked_r_metadata.return_value = [] self.mocked_r_metadata.return_value = []
repo = Repository("backup") repo = Repository("/tmp/backup")
self.assertIsInstance(repo.create_snapshot(), Snapshot) self.assertIsInstance(repo.create_snapshot(), Snapshot)
def test_create_duplicate_snapshot(self): def test_create_duplicate_snapshot(self):
# Test that if a snapshot is a duplicate, then return that duplicate snapshot # Test that if a snapshot is a duplicate, then return that duplicate snapshot
self.mocked_r_metadata.return_value = [] self.mocked_r_metadata.return_value = []
repo = Repository("backup") repo = Repository("/tmp/backup")
name = "new-snapshot" name = "new-snapshot"
first = repo.create_snapshot(name) first = repo.create_snapshot(name)
@ -237,21 +237,21 @@ class TestRepositoryCleanup(unittest.TestCase):
self.mocked_shutil.rmtree.assert_not_called() self.mocked_shutil.rmtree.assert_not_called()
def test_removes_metadata_by_default(self): def test_removes_metadata_by_default(self):
repo = Repository("backup") repo = Repository("/tmp/backup")
repo.cleanup() repo.cleanup()
self.mocked_path.return_value.unlink.assert_called_once() self.mocked_path.return_value.unlink.assert_called_once()
def test_removes_snapshots(self): def test_removes_snapshots(self):
repo = Repository("backup") repo = Repository("/tmp/backup")
repo.cleanup(remove_snapshots=True) repo.cleanup(remove_snapshots=True)
self.mocked_shutil.rmtree.assert_called_once() self.mocked_shutil.rmtree.assert_called_once()
def test_removes_repo_dir(self): def test_removes_repo_dir(self):
repo = Repository("backup") repo = Repository("/tmp/backup")
repo.cleanup(remove_repo_dir=True) repo.cleanup(remove_repo_dir=True)