Update input data parameters and restructure test methods

This commit is contained in:
Eric Torres 2019-04-11 22:18:42 -07:00
parent 2b1caf459c
commit ceadeed216

View File

@ -67,24 +67,16 @@ class TestRepositoryPreCreate(unittest.TestCase):
else: else:
self.assertFalse(repo.empty) self.assertFalse(repo.empty)
@given( @given(lists(from_regex(VALID_SNAPSHOT_NAME, fullmatch=True), unique=True))
lists( def test_dunder_len(self, snapshots):
text(
alphabet=characters(blacklist_characters=UNWANTED_SNAPSHOT_CHARS),
min_size=1,
),
unique=True,
)
)
def test_len(self, snapshots):
self.mocked_r_metadata.return_value = snapshots.copy() self.mocked_r_metadata.return_value = snapshots.copy()
repo = Repository("backup") repo = Repository("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_contains(self, name): def test_dunder_contains(self, name):
self.mocked_r_metadata = [] self.mocked_r_metadata.return_value = []
repo = Repository("backup") repo = Repository("backup")
self.assertFalse(name in repo) self.assertFalse(name in repo)
@ -99,8 +91,17 @@ 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):
r = Repository("backup") repo = Repository("backup")
self.assertListEqual(r.snapshots, []) self.assertListEqual(repo.snapshots, [])
@given(
lists(from_regex(VALID_SNAPSHOT_NAME, fullmatch=True), min_size=1, unique=True)
)
def snapshots_property_contains_snapshot_objects(self, snapshots):
self.mocked_r_metadata.return_value = snapshots
repo = Repository("backup")
self.assertTrue(all(isinstance(p, Snapshot) for p in repo))
def tearDown(self): def tearDown(self):
self.patched_path.stop() self.patched_path.stop()
@ -149,7 +150,8 @@ class TestRepositoryPostCreate(unittest.TestCase):
repo.create_snapshot() repo.create_snapshot()
self.assertFalse(repo.empty) self.assertEqual(len(repo), len(snapshots) + 1)
self.assertEqual(len(repo.snapshots), len(snapshots) + 1)
@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):
@ -165,20 +167,24 @@ class TestRepositoryPostCreate(unittest.TestCase):
repo.create_snapshot() repo.create_snapshot()
self.assertEqual(len(repo), len(snapshots) + 1) self.assertFalse(repo.empty)
self.assertEqual(len(repo.snapshots), len(snapshots) + 1)
@given( def test_snapshot_returns_snapshot_object(self):
text( self.mocked_r_metadata.return_value = []
alphabet=characters(blacklist_characters=UNWANTED_SNAPSHOT_CHARS),
min_size=1,
)
)
def test_contains(self, name):
self.mocked_path.return_value.exists.return_value = False
repo = Repository("backup") repo = Repository("backup")
repo.create_snapshot(name) self.assertIsInstance(repo.create_snapshot(), Snapshot)
def test_create_duplicate_snapshot(self):
# Test that if a snapshot is a duplicate, then return that duplicate snapshot
self.mocked_r_metadata.return_value = []
repo = Repository("backup")
name = "new-snapshot"
first = repo.create_snapshot(name)
second = repo.create_snapshot(name)
self.assertIs(first, second)
self.assertTrue(name in repo) self.assertTrue(name in repo)
self.assertEqual(len(repo), 1) self.assertEqual(len(repo), 1)