From 5e8bef7c728dfd58afb03aac633818877a12923d Mon Sep 17 00:00:00 2001 From: Vladimir Diaz Date: Thu, 10 Nov 2016 16:58:59 -0500 Subject: [PATCH] Add some coverage for repository_tool.py --- tests/test_repository_tool.py | 13 +++++++++++++ tuf/repository_tool.py | 11 +++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/test_repository_tool.py b/tests/test_repository_tool.py index 08182587..1240d64f 100755 --- a/tests/test_repository_tool.py +++ b/tests/test_repository_tool.py @@ -381,11 +381,16 @@ def test_get_filepaths_in_directory(self): 'snapshot.json', 'snapshot.json.gz', 'timestamp.json', 'timestamp.json.gz', 'role1.json', 'role1.json.gz', 'role2.json', 'role2.json.gz'] + basenames = [] for filepath in metadata_files: basenames.append(os.path.basename(filepath)) self.assertEqual(sorted(expected_files), sorted(basenames)) + # Test when 'recursive_walk' is True. + metadata_files = repo.get_filepaths_in_directory(metadata_directory, + recursive_walk=True) + # Test improperly formatted arguments. self.assertRaises(tuf.ssl_commons.exceptions.FormatError, repo.get_filepaths_in_directory, 3, recursive_walk=False, followlinks=False) @@ -1016,6 +1021,14 @@ def test_delegations(self): + def test_add_delegated_role(self): + # Test for invalid targets object. + self.assertRaises(tuf.ssl_commons.exceptions.FormatError, + self.targets_object.add_delegated_role, 'targets', + 'bad_object') + + + def test_add_target(self): # Test normal case. # Verify the targets object initially contains zero target files. diff --git a/tuf/repository_tool.py b/tuf/repository_tool.py index fc379f95..2e2278a5 100755 --- a/tuf/repository_tool.py +++ b/tuf/repository_tool.py @@ -530,10 +530,13 @@ def get_filepaths_in_directory(files_directory, recursive_walk=False, targets.append(full_target_path) # Prune the subdirectories to walk right now if we do not wish to - # recursively walk files_directory. + # recursively walk 'files_directory'. if recursive_walk is False: del dirnames[:] + else: + logger.debug('Not pruning subdirectories ' + repr(dirnames)) + return targets @@ -544,9 +547,9 @@ class Metadata(object): """ Provide a base class to represent a TUF Metadata role. There are four - top-level roles: Root, Targets, Snapshot, and Timestamp. The Metadata class - provides methods that are needed by all top-level roles, such as adding - and removing public keys, private keys, and signatures. Metadata + top-level roles: Root, Targets, Snapshot, and Timestamp. The Metadata + class provides methods that are needed by all top-level roles, such as + adding and removing public keys, private keys, and signatures. Metadata attributes, such as rolename, version, threshold, expiration, key list, and compressions, is also provided by the Metadata base class.