Changeset View
Changeset View
Standalone View
Standalone View
swh/web/ui/tests/test_converters.py
Show First 20 Lines • Show All 338 Lines • ▼ Show 20 Lines | def from_revision(self): | ||||
'archive_type': 'tar', | 'archive_type': 'tar', | ||||
'name': 'webbase-5.7.0.tar.gz', | 'name': 'webbase-5.7.0.tar.gz', | ||||
'sha1': '147f73f369733d088b7a6fa9c4e0273dcd3c7ccd', | 'sha1': '147f73f369733d088b7a6fa9c4e0273dcd3c7ccd', | ||||
'sha1_git': '6a15ea8b881069adedf11feceec35588f2cfe8f1', | 'sha1_git': '6a15ea8b881069adedf11feceec35588f2cfe8f1', | ||||
'sha256': '401d0df797110bea805d358b85bcc1ced29549d3d73f' | 'sha256': '401d0df797110bea805d358b85bcc1ced29549d3d73f' | ||||
'309d36484e7edf7bb912' | '309d36484e7edf7bb912' | ||||
}] | }] | ||||
}, | }, | ||||
'merge': True | |||||
} | |||||
# when | |||||
actual_revision = converters.from_revision(revision_input) | |||||
# then | |||||
self.assertEqual(actual_revision, expected_revision) | |||||
@istest | |||||
def from_revision_nomerge(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', | |||||
zack: several constants here seem to be reused in multiple tests, at least:
- the commit id
- the… | |||||
Not Done Inline ActionsI'd rather remove these entirely than define them as constants, since they're irrelevant to the tests I'm performing. Does that seem fair? jbertran: I'd rather remove these entirely than define them as constants, since they're irrelevant to the… | |||||
Not Done Inline ActionsSure. Just note it down as low priority task, maybe? zack: Sure. Just note it down as low priority task, maybe? | |||||
'email': b'robot@softwareheritage.org', | |||||
}, | |||||
'message': b'synthetic revision message', | |||||
'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') | |||||
], | |||||
'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': 'synthetic revision message', | |||||
'date': "2000-01-17T11:23:54+00:00", | |||||
'committer_date': "2000-01-17T11:23:54+00:00", | |||||
'children': [ | |||||
'123546353ed3480476f032475e7c244eff7371d5' | |||||
], | |||||
'parents': [ | |||||
'29d8be353ed3480476f032475e7c244eff7371d5' | |||||
], | |||||
'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' | |||||
}] | |||||
}, | |||||
'merge': False | |||||
} | |||||
# when | |||||
actual_revision = converters.from_revision(revision_input) | |||||
# then | |||||
self.assertEqual(actual_revision, expected_revision) | |||||
@istest | |||||
def from_revision_noparents(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'synthetic revision message', | |||||
'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', | |||||
'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' | |||||
Not Done Inline Actionsdetails about this artifact look like other candidates for defining constants/attributes, and referencing them from multiple tests zack: details about this artifact look like other candidates for defining constants/attributes, and… | |||||
Not Done Inline ActionsSame here. jbertran: Same here. | |||||
'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': 'synthetic revision message', | |||||
'date': "2000-01-17T11:23:54+00:00", | |||||
'committer_date': "2000-01-17T11:23:54+00:00", | |||||
'children': [ | |||||
'123546353ed3480476f032475e7c244eff7371d5' | |||||
], | |||||
'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 | # 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) | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | def from_revision_invalid(self): | ||||
'archive_type': 'tar', | 'archive_type': 'tar', | ||||
'name': 'webbase-5.7.0.tar.gz', | 'name': 'webbase-5.7.0.tar.gz', | ||||
'sha1': '147f73f369733d088b7a6fa9c4e0273dcd3c7ccd', | 'sha1': '147f73f369733d088b7a6fa9c4e0273dcd3c7ccd', | ||||
'sha1_git': '6a15ea8b881069adedf11feceec35588f2cfe8f1', | 'sha1_git': '6a15ea8b881069adedf11feceec35588f2cfe8f1', | ||||
'sha256': '401d0df797110bea805d358b85bcc1ced29549d3d73f' | 'sha256': '401d0df797110bea805d358b85bcc1ced29549d3d73f' | ||||
'309d36484e7edf7bb912' | '309d36484e7edf7bb912' | ||||
}] | }] | ||||
}, | }, | ||||
'merge': True | |||||
} | } | ||||
# 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) | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |
several constants here seem to be reused in multiple tests, at least:
please define them either as module-level constants, or as class-level attributes of the test module, and reference them from the various tests where they are used (using self.* or not, depending on the choice)