From 031bd1b482dbbbb36159c14d648efb3e7aba63d6 Mon Sep 17 00:00:00 2001 From: Lukas Puehringer Date: Sat, 30 Nov 2019 12:41:18 +0100 Subject: [PATCH] test: Assert tutorial delegate_hashed_bins output Signed-off-by: Lukas Puehringer --- tests/test_tutorial.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/test_tutorial.py b/tests/test_tutorial.py index e45bb922..b2633778 100644 --- a/tests/test_tutorial.py +++ b/tests/test_tutorial.py @@ -341,8 +341,27 @@ def test_tutorial(self): targets = repository.get_filepaths_in_directory( os.path.join('repository', 'targets', 'myproject'), recursive_walk=True) - repository.targets('unclaimed').delegate_hashed_bins( - targets, [public_unclaimed_key], 32) + # Patch logger to assert that it accurately logs the output of hashed bin + # delegation. The logger is called multiple times, first with info level + # then with warning level. So we have to assert for the accurate sequence + # of calls or rather its call arguments. + with mock.patch("tuf.repository_tool.logger") as mock_logger: + repository.targets('unclaimed').delegate_hashed_bins( + targets, [public_unclaimed_key], 32) + + self.assertListEqual([ + "Creating hashed bin delegations.", + "1 total targets.", + "32 hashed bins.", + "256 total hash prefixes.", + "Each bin ranges over 8 hash prefixes." + ] + ["Adding a verification key that has already been used."] * 32, + [ + args[0] for args, _ in + mock_logger.info.call_args_list + mock_logger.warning.call_args_list + ]) + + for delegation in repository.targets('unclaimed').delegations: delegation.load_signing_key(private_unclaimed_key)