Skip to content

Commit 0498991

Browse files
committed
Add new generate_snapshot_metadata syntax to test_repository_lib
Signed-off-by: marinamoore <mnm678@gmail.com>
1 parent 7d42235 commit 0498991

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

tests/test_repository_lib.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -476,33 +476,33 @@ def test_build_merkle_tree(self):
476476
test_nodes = {}
477477
test_nodes['file1'] = tuf.formats.make_metadata_fileinfo(5, None, None)
478478

479-
root_1, leaves = repo_lib.build_merkle_tree(test_nodes)
480-
repo_lib.write_merkle_paths(root_1, leaves, storage_backend,
479+
root_1, leaves = repo_lib._build_merkle_tree(test_nodes)
480+
repo_lib._write_merkle_paths(root_1, leaves, storage_backend,
481481
temporary_directory)
482482

483483
file_path = os.path.join(temporary_directory, 'file1-snapshot.json')
484484
self.assertTrue(os.path.exists(file_path))
485485

486486
test_nodes['file2'] = tuf.formats.make_metadata_fileinfo(5, None, None)
487-
root_2, leaves = repo_lib.build_merkle_tree(test_nodes)
487+
root_2, leaves = repo_lib._build_merkle_tree(test_nodes)
488488

489-
self.assertEqual(root_2.left().hash(), root_1.hash())
489+
self.assertEqual(root_2.left.digest, root_1.digest)
490490

491491
test_nodes['file3'] = tuf.formats.make_metadata_fileinfo(5, None, None)
492492
test_nodes['file4'] = tuf.formats.make_metadata_fileinfo(5, None, None)
493493

494-
root_3, leaves = repo_lib.build_merkle_tree(test_nodes)
494+
root_3, leaves = repo_lib._build_merkle_tree(test_nodes)
495495

496-
self.assertEqual(root_3.left().hash(), root_2.hash())
496+
self.assertEqual(root_3.left.digest, root_2.digest)
497497

498498
test_nodes['file5'] = tuf.formats.make_metadata_fileinfo(5, None, None)
499499

500-
root_4, leaves = repo_lib.build_merkle_tree(test_nodes)
500+
root_4, leaves = repo_lib._build_merkle_tree(test_nodes)
501501

502-
repo_lib.write_merkle_paths(root_4, leaves, storage_backend,
502+
repo_lib._write_merkle_paths(root_4, leaves, storage_backend,
503503
temporary_directory)
504504

505-
self.assertEqual(root_4.left().hash(), root_3.hash())
505+
self.assertEqual(root_4.left.digest, root_3.digest)
506506

507507
# Ensure that the paths are written to the directory
508508
file_path = os.path.join(temporary_directory, 'file1-snapshot.json')
@@ -516,7 +516,7 @@ def test_build_merkle_tree(self):
516516
test_nodes['role1'] = tuf.formats.make_metadata_fileinfo(1, None, None)
517517
test_nodes['role2'] = tuf.formats.make_metadata_fileinfo(1, None, None)
518518

519-
root, leaves = repo_lib.build_merkle_tree(test_nodes)
519+
root, leaves = repo_lib._build_merkle_tree(test_nodes)
520520

521521

522522

@@ -566,7 +566,7 @@ def test_generate_snapshot_metadata(self):
566566
repo_lib.generate_snapshot_metadata(metadata_directory, version,
567567
expiration_date,
568568
storage_backend,
569-
consistent_snapshot=False)
569+
consistent_snapshot=False)[0]
570570
self.assertTrue(tuf.formats.SNAPSHOT_SCHEMA.matches(snapshot_metadata))
571571

572572

@@ -595,7 +595,7 @@ def test_generate_snapshot_metadata_with_length(self):
595595
expiration_date,
596596
storage_backend,
597597
consistent_snapshot=False,
598-
use_length=True)
598+
use_length=True)[0]
599599
self.assertTrue(tuf.formats.SNAPSHOT_SCHEMA.matches(snapshot_metadata))
600600

601601
metadata_files_info_dict = snapshot_metadata['meta']
@@ -610,7 +610,8 @@ def test_generate_snapshot_metadata_with_length(self):
610610
# In the repository, the file "role_file.xml" have been added to make
611611
# sure that non-json files aren't loaded. This file should be filtered.
612612
if stripped_filename.endswith('.json'):
613-
if stripped_filename not in TOP_LEVEL_METADATA_FILES:
613+
if stripped_filename not in TOP_LEVEL_METADATA_FILES and \
614+
not stripped_filename.endswith('-snapshot.json'):
614615
# Check that length is not calculated but hashes is
615616
self.assertIn('length', metadata_files_info_dict[stripped_filename])
616617
self.assertNotIn('hashes', metadata_files_info_dict[stripped_filename])
@@ -626,7 +627,7 @@ def test_generate_snapshot_metadata_with_hashes(self):
626627
expiration_date,
627628
storage_backend,
628629
consistent_snapshot=False,
629-
use_hashes=True)
630+
use_hashes=True)[0]
630631
self.assertTrue(tuf.formats.SNAPSHOT_SCHEMA.matches(snapshot_metadata))
631632

632633
metadata_files_info_dict = snapshot_metadata['meta']
@@ -641,7 +642,8 @@ def test_generate_snapshot_metadata_with_hashes(self):
641642
# In the repository, the file "role_file.xml" have been added to make
642643
# sure that non-json files aren't loaded. This file should be filtered.
643644
if stripped_filename.endswith('.json'):
644-
if stripped_filename not in TOP_LEVEL_METADATA_FILES:
645+
if stripped_filename not in TOP_LEVEL_METADATA_FILES and \
646+
not stripped_filename.endswith('-snapshot.json'):
645647
# Check that hashes is not calculated but length is
646648
self.assertNotIn('length', metadata_files_info_dict[stripped_filename])
647649
self.assertIn('hashes', metadata_files_info_dict[stripped_filename])
@@ -658,7 +660,7 @@ def test_generate_snapshot_metadata_with_hashes_and_length(self):
658660
storage_backend,
659661
consistent_snapshot=False,
660662
use_length=True,
661-
use_hashes=True)
663+
use_hashes=True)[0]
662664
self.assertTrue(tuf.formats.SNAPSHOT_SCHEMA.matches(snapshot_metadata))
663665

664666
metadata_files_info_dict = snapshot_metadata['meta']
@@ -673,7 +675,8 @@ def test_generate_snapshot_metadata_with_hashes_and_length(self):
673675
# In the repository, the file "role_file.xml" have been added to make
674676
# sure that non-json files aren't loaded. This file should be filtered.
675677
if stripped_filename.endswith('.json'):
676-
if stripped_filename not in TOP_LEVEL_METADATA_FILES:
678+
if stripped_filename not in TOP_LEVEL_METADATA_FILES and \
679+
not stripped_filename.endswith('-snapshot.json'):
677680
# Check that both length and hashes are not are not calculated
678681
self.assertIn('length', metadata_files_info_dict[stripped_filename])
679682
self.assertIn('hashes', metadata_files_info_dict[stripped_filename])

0 commit comments

Comments
 (0)