Changeset View
Changeset View
Standalone View
Standalone View
swh/web/ui/tests/test_converters.py
Show First 20 Lines • Show All 320 Lines • ▼ Show 20 Lines | def from_revision(self): | ||||
# when | # when | ||||
actual_revision = converters.from_revision(revision_input) | actual_revision = converters.from_revision(revision_input) | ||||
# then | # then | ||||
self.assertEqual(actual_revision, expected_revision) | self.assertEqual(actual_revision, expected_revision) | ||||
@istest | @istest | ||||
def from_revision_invalid(self): | |||||
revision_input = { | |||||
'id': hashutil.hex_to_hash( | |||||
'18d8be353ed3480476f032475e7c233eff7371d5'), | |||||
'directory': hashutil.hex_to_hash( | |||||
'7834ef7e7c357ce2af928115c6c6a42b7e2a44e6'), | |||||
'author': { | |||||
'name': b'Software Heritage', | |||||
'fullname': b'robot robot@softwareheritage.org', | |||||
'email': b'robot@softwareheritage.org', | |||||
}, | |||||
'committer': { | |||||
'name': b'Software Heritage', | |||||
'fullname': b'robot robot@softwareheritage.org', | |||||
'email': b'robot@softwareheritage.org', | |||||
}, | |||||
'message': b'invalid message \xff', | |||||
'date': { | |||||
'timestamp': datetime.datetime( | |||||
2000, 1, 17, 11, 23, 54, | |||||
tzinfo=datetime.timezone.utc).timestamp(), | |||||
'offset': 0, | |||||
'negative_utc': False, | |||||
}, | |||||
'committer_date': { | |||||
'timestamp': datetime.datetime( | |||||
2000, 1, 17, 11, 23, 54, | |||||
tzinfo=datetime.timezone.utc).timestamp(), | |||||
'offset': 0, | |||||
'negative_utc': False, | |||||
}, | |||||
'synthetic': True, | |||||
'type': 'tar', | |||||
'parents': [ | |||||
hashutil.hex_to_hash( | |||||
'29d8be353ed3480476f032475e7c244eff7371d5'), | |||||
hashutil.hex_to_hash( | |||||
'30d8be353ed3480476f032475e7c244eff7371d5') | |||||
], | |||||
'children': [ | |||||
hashutil.hex_to_hash( | |||||
'123546353ed3480476f032475e7c244eff7371d5'), | |||||
], | |||||
'metadata': { | |||||
'original_artifact': [{ | |||||
'archive_type': 'tar', | |||||
'name': 'webbase-5.7.0.tar.gz', | |||||
'sha1': '147f73f369733d088b7a6fa9c4e0273dcd3c7ccd', | |||||
'sha1_git': '6a15ea8b881069adedf11feceec35588f2cfe8f1', | |||||
'sha256': '401d0df797110bea805d358b85bcc1ced29549d3d73f' | |||||
'309d36484e7edf7bb912', | |||||
}] | |||||
}, | |||||
} | |||||
expected_revision = { | |||||
'id': '18d8be353ed3480476f032475e7c233eff7371d5', | |||||
'directory': '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6', | |||||
'author': { | |||||
'name': 'Software Heritage', | |||||
'fullname': 'robot robot@softwareheritage.org', | |||||
'email': 'robot@softwareheritage.org', | |||||
}, | |||||
'committer': { | |||||
'name': 'Software Heritage', | |||||
'fullname': 'robot robot@softwareheritage.org', | |||||
'email': 'robot@softwareheritage.org', | |||||
}, | |||||
'message': None, | |||||
'msg_url': '/api/1/revision/' | |||||
'18d8be353ed3480476f032475e7c233eff7371d5/raw/', | |||||
'date': "2000-01-17T11:23:54+00:00", | |||||
'committer_date': "2000-01-17T11:23:54+00:00", | |||||
'children': [ | |||||
'123546353ed3480476f032475e7c244eff7371d5' | |||||
], | |||||
'parents': [ | |||||
'29d8be353ed3480476f032475e7c244eff7371d5', | |||||
'30d8be353ed3480476f032475e7c244eff7371d5' | |||||
], | |||||
'type': 'tar', | |||||
'synthetic': True, | |||||
'metadata': { | |||||
'original_artifact': [{ | |||||
'archive_type': 'tar', | |||||
'name': 'webbase-5.7.0.tar.gz', | |||||
'sha1': '147f73f369733d088b7a6fa9c4e0273dcd3c7ccd', | |||||
'sha1_git': '6a15ea8b881069adedf11feceec35588f2cfe8f1', | |||||
'sha256': '401d0df797110bea805d358b85bcc1ced29549d3d73f' | |||||
'309d36484e7edf7bb912' | |||||
}] | |||||
}, | |||||
} | |||||
# when | |||||
actual_revision = converters.from_revision(revision_input) | |||||
# then | |||||
self.assertEqual(actual_revision, expected_revision) | |||||
@istest | |||||
def from_content(self): | def from_content(self): | ||||
content_input = { | content_input = { | ||||
'sha1': hashutil.hex_to_hash('5c6f0e2750f48fa0bd0c4cf5976ba0b9e0' | 'sha1': hashutil.hex_to_hash('5c6f0e2750f48fa0bd0c4cf5976ba0b9e0' | ||||
'2ebda5'), | '2ebda5'), | ||||
'sha256': hashutil.hex_to_hash('39007420ca5de7cb3cfc15196335507e' | 'sha256': hashutil.hex_to_hash('39007420ca5de7cb3cfc15196335507e' | ||||
'e76c98930e7e0afa4d2747d3bf96c926'), | 'e76c98930e7e0afa4d2747d3bf96c926'), | ||||
'sha1_git': hashutil.hex_to_hash('40e71b8614fcd89ccd17ca2b1d9e66' | 'sha1_git': hashutil.hex_to_hash('40e71b8614fcd89ccd17ca2b1d9e66' | ||||
'c5b00a6d03'), | 'c5b00a6d03'), | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |