diff --git a/swh/loader/pypi/tests/test_loader.py b/swh/loader/pypi/tests/test_loader.py --- a/swh/loader/pypi/tests/test_loader.py +++ b/swh/loader/pypi/tests/test_loader.py @@ -87,7 +87,7 @@ _dir_id = hashutil.hash_to_hex(_dir['id']) self.assertIn(_dir_id, expected_directories) - def assertSnapshotOk(self, expected_snapshot, expected_revisions): + def assertSnapshotOk(self, expected_snapshot, expected_branches): snapshots = self.loader.all_snapshots self.assertEqual(len(snapshots), 1) @@ -95,13 +95,14 @@ snap_id = hashutil.hash_to_hex(snap['id']) self.assertEqual(snap_id, expected_snapshot) - branches = snap['branches'] - self.assertEqual(len(expected_revisions), len(branches)) - - for branch, target in branches.items(): - rev_id = hashutil.hash_to_hex(target['target']) - self.assertIn(rev_id, expected_revisions) - self.assertEqual('revision', target['target_type']) + branches = { + branch.decode('utf-8'): { + 'target': hashutil.hash_to_hex(t['target']), + 'target_type': t['target_type'], + } if t else t + for branch, t in snap['branches'].items() + } + self.assertEqual(expected_branches, branches) def assertRevisionsOk(self, expected_revisions): # noqa: N802 """Check the loader's revisions match the expected revisions. @@ -187,8 +188,19 @@ } self.assertRevisionsOk(expected_revisions) + expected_branches = { + '0805nexter-1.1.0.zip': { + 'target': '4c99891f93b81450385777235a37b5e966dd1571', + 'target_type': 'revision', + }, + '0805nexter-1.2.0.zip': { + 'target': 'e445da4da22b31bfebb6ffc4383dbf839a074d21', + 'target_type': 'revision', + }, + } + self.assertSnapshotOk('f456b03e8bf1920d64b00df234b1efedc25b6c93', - expected_revisions) + expected_branches) class PyPILoaderWithSnapshot(TestPyPILoader): @@ -261,13 +273,18 @@ self.assertDirectoriesOk([]) self.assertRevisionsOk(expected_revisions={}) - expected_revisions = { - '4c99891f93b81450385777235a37b5e966dd1571': '05219ba38bc542d4345d5638af1ed56c7d43ca7d', # noqa - 'e445da4da22b31bfebb6ffc4383dbf839a074d21': 'b178b66bd22383d5f16f4f5c923d39ca798861b4', # noqa - } expected_snapshot_id = 'f456b03e8bf1920d64b00df234b1efedc25b6c93' - self.assertSnapshotOk('f456b03e8bf1920d64b00df234b1efedc25b6c93', - expected_revisions) + expected_branches = { + '0805nexter-1.1.0.zip': { + 'target': '4c99891f93b81450385777235a37b5e966dd1571', + 'target_type': 'revision', + }, + '0805nexter-1.2.0.zip': { + 'target': 'e445da4da22b31bfebb6ffc4383dbf839a074d21', + 'target_type': 'revision', + }, + } + self.assertSnapshotOk(expected_snapshot_id, expected_branches) _id = hashutil.hash_to_hex(self.loader._last_snapshot()['id']) self.assertEquals(expected_snapshot_id, _id) @@ -342,7 +359,22 @@ expected_revisions[rev] = dir_id expected_snapshot_id = 'e5beda90e9ddbc8672734ed172246b06fcbc6827' - self.assertSnapshotOk(expected_snapshot_id, expected_revisions) + expected_branches = { + '0805nexter-1.1.0.zip': { + 'target': '4c99891f93b81450385777235a37b5e966dd1571', + 'target_type': 'revision', + }, + '0805nexter-1.2.0.zip': { + 'target': 'e445da4da22b31bfebb6ffc4383dbf839a074d21', + 'target_type': 'revision', + }, + '0805nexter-1.3.0.zip': { + 'target': 'fb46e49605b0bbe69f8c53d315e89370e7c6cb5d', + 'target_type': 'revision', + }, + } + + self.assertSnapshotOk(expected_snapshot_id, expected_branches) _id = hashutil.hash_to_hex(self.loader._last_snapshot()['id']) self.assertNotEqual(expected_snapshot_id, _id) @@ -455,17 +487,22 @@ } self.assertRevisionsOk(expected_revisions) - old_revisions = { - # 1.2.0 - 'e445da4da22b31bfebb6ffc4383dbf839a074d21': 'b178b66bd22383d5f16f4f5c923d39ca798861b4', # noqa - # 1.3.0 - 'fb46e49605b0bbe69f8c53d315e89370e7c6cb5d': 'e226e7e4ad03b4fc1403d69a18ebdd6f2edd2b3a', # noqa - } - for rev, dir_id in old_revisions.items(): - expected_revisions[rev] = dir_id - expected_snapshot_id = 'fb192f35397812776377fa758e0ba4cf20a4cf5d' - self.assertSnapshotOk(expected_snapshot_id, expected_revisions) + expected_branches = { + '0805nexter-1.2.0.zip': { + 'target': 'e445da4da22b31bfebb6ffc4383dbf839a074d21', + 'target_type': 'revision', + }, + '0805nexter-1.3.0.zip': { + 'target': 'fb46e49605b0bbe69f8c53d315e89370e7c6cb5d', + 'target_type': 'revision', + }, + '0805nexter-1.4.0.zip': { + 'target': '5e91875f096ac48c98d74acf307439a3490f2827', + 'target_type': 'revision', + }, + } + self.assertSnapshotOk(expected_snapshot_id, expected_branches) _id = hashutil.hash_to_hex(self.loader._last_snapshot()['id']) self.assertNotEqual(expected_snapshot_id, _id)