Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/common/test_converters.py
# Copyright (C) 2015-2018 The Software Heritage developers | # Copyright (C) 2015-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import datetime | import datetime | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.web.common import converters | from swh.web.common import converters | ||||
from swh.web.tests.testcase import WebTestCase | |||||
class ConvertersTestCase(WebTestCase): | |||||
def test_fmap(self): | def test_fmap(): | ||||
self.assertEqual([2, 3, None, 4], | assert [2, 3, None, 4] == converters.fmap(lambda x: x+1, [1, 2, None, 3]) | ||||
converters.fmap(lambda x: x+1, [1, 2, None, 3])) | assert [11, 12, 13] == list(converters.fmap(lambda x: x+10, | ||||
self.assertEqual([11, 12, 13], | map(lambda x: x, [1, 2, 3]))) | ||||
list(converters.fmap(lambda x: x+10, | assert {'a': 2, 'b': 4} == converters.fmap(lambda x: x*2, {'a': 1, 'b': 2}) | ||||
map(lambda x: x, [1, 2, 3])))) | assert 100 == converters.fmap(lambda x: x*10, 10) | ||||
self.assertEqual({'a': 2, 'b': 4}, | assert {'a': [2, 6], 'b': 4} == converters.fmap(lambda x: x*2, | ||||
converters.fmap(lambda x: x*2, {'a': 1, 'b': 2})) | {'a': [1, 3], 'b': 2}) | ||||
self.assertEqual(100, | assert converters.fmap(lambda x: x, None) is None | ||||
converters.fmap(lambda x: x*10, 10)) | |||||
self.assertEqual({'a': [2, 6], 'b': 4}, | |||||
converters.fmap(lambda x: x*2, {'a': [1, 3], 'b': 2})) # noqa | |||||
self.assertIsNone(converters.fmap(lambda x: x, None)) | |||||
def test_from_swh(self): | def test_from_swh(): | ||||
some_input = { | some_input = { | ||||
'a': 'something', | 'a': 'something', | ||||
'b': 'someone', | 'b': 'someone', | ||||
'c': b'sharp-0.3.4.tgz', | 'c': b'sharp-0.3.4.tgz', | ||||
'd': hashutil.hash_to_bytes( | 'd': hashutil.hash_to_bytes( | ||||
'b04caf10e9535160d90e874b45aa426de762f19f'), | 'b04caf10e9535160d90e874b45aa426de762f19f'), | ||||
'e': b'sharp.html/doc_002dS_005fISREG.html', | 'e': b'sharp.html/doc_002dS_005fISREG.html', | ||||
'g': [b'utf-8-to-decode', b'another-one'], | 'g': [b'utf-8-to-decode', b'another-one'], | ||||
'h': 'something filtered', | 'h': 'something filtered', | ||||
'i': {'e': b'something'}, | 'i': {'e': b'something'}, | ||||
'j': { | 'j': { | ||||
'k': { | 'k': { | ||||
'l': [b'bytes thing', b'another thingy', b''], | 'l': [b'bytes thing', b'another thingy', b''], | ||||
'n': 'dont care either' | 'n': 'dont care either' | ||||
}, | }, | ||||
'm': 'dont care' | 'm': 'dont care' | ||||
}, | }, | ||||
'o': 'something', | 'o': 'something', | ||||
'p': b'foo', | 'p': b'foo', | ||||
'q': {'extra-headers': [['a', b'intact']]}, | 'q': {'extra-headers': [['a', b'intact']]}, | ||||
'w': None, | 'w': None, | ||||
'r': {'p': 'also intact', | 'r': {'p': 'also intact', | ||||
'q': 'bar'}, | 'q': 'bar'}, | ||||
's': { | 's': { | ||||
'timestamp': 42, | 'timestamp': 42, | ||||
'offset': -420, | 'offset': -420, | ||||
'negative_utc': None, | 'negative_utc': None, | ||||
}, | }, | ||||
's1': { | 's1': { | ||||
'timestamp': {'seconds': 42, 'microseconds': 0}, | 'timestamp': {'seconds': 42, 'microseconds': 0}, | ||||
'offset': -420, | 'offset': -420, | ||||
'negative_utc': None, | 'negative_utc': None, | ||||
}, | }, | ||||
's2': datetime.datetime( | 's2': datetime.datetime( | ||||
2013, 7, 1, 20, 0, 0, | 2013, 7, 1, 20, 0, 0, | ||||
tzinfo=datetime.timezone.utc), | tzinfo=datetime.timezone.utc), | ||||
't': None, | 't': None, | ||||
'u': None, | 'u': None, | ||||
'v': None, | 'v': None, | ||||
'x': None, | 'x': None, | ||||
} | } | ||||
expected_output = { | expected_output = { | ||||
'a': 'something', | 'a': 'something', | ||||
'b': 'someone', | 'b': 'someone', | ||||
'c': 'sharp-0.3.4.tgz', | 'c': 'sharp-0.3.4.tgz', | ||||
'd': 'b04caf10e9535160d90e874b45aa426de762f19f', | 'd': 'b04caf10e9535160d90e874b45aa426de762f19f', | ||||
'e': 'sharp.html/doc_002dS_005fISREG.html', | 'e': 'sharp.html/doc_002dS_005fISREG.html', | ||||
'g': ['utf-8-to-decode', 'another-one'], | 'g': ['utf-8-to-decode', 'another-one'], | ||||
'i': {'e': 'something'}, | 'i': {'e': 'something'}, | ||||
'j': { | 'j': { | ||||
'k': { | 'k': { | ||||
'l': ['bytes thing', 'another thingy', ''] | 'l': ['bytes thing', 'another thingy', ''] | ||||
} | } | ||||
}, | }, | ||||
'p': 'foo', | 'p': 'foo', | ||||
'q': {'extra-headers': [['a', 'intact']]}, | 'q': {'extra-headers': [['a', 'intact']]}, | ||||
'w': {}, | 'w': {}, | ||||
'r': {'p': 'also intact', | 'r': {'p': 'also intact', | ||||
'q': 'bar'}, | 'q': 'bar'}, | ||||
's': '1969-12-31T17:00:42-07:00', | 's': '1969-12-31T17:00:42-07:00', | ||||
's1': '1969-12-31T17:00:42-07:00', | 's1': '1969-12-31T17:00:42-07:00', | ||||
's2': '2013-07-01T20:00:00+00:00', | 's2': '2013-07-01T20:00:00+00:00', | ||||
'u': {}, | 'u': {}, | ||||
'v': [], | 'v': [], | ||||
'x': None, | 'x': None, | ||||
} | } | ||||
actual_output = converters.from_swh( | actual_output = converters.from_swh( | ||||
some_input, | some_input, | ||||
hashess={'d', 'o', 'x'}, | hashess={'d', 'o', 'x'}, | ||||
bytess={'c', 'e', 'g', 'l'}, | bytess={'c', 'e', 'g', 'l'}, | ||||
dates={'s', 's1', 's2'}, | dates={'s', 's1', 's2'}, | ||||
blacklist={'h', 'm', 'n', 'o'}, | blacklist={'h', 'm', 'n', 'o'}, | ||||
removables_if_empty={'t'}, | removables_if_empty={'t'}, | ||||
empty_dict={'u'}, | empty_dict={'u'}, | ||||
empty_list={'v'}, | empty_list={'v'}, | ||||
convert={'p', 'q', 'w'}, | convert={'p', 'q', 'w'}, | ||||
convert_fn=converters.convert_revision_metadata) | convert_fn=converters.convert_revision_metadata) | ||||
self.assertEqual(expected_output, actual_output) | assert expected_output == actual_output | ||||
def test_from_swh_edge_cases_do_no_conversion_if_none_or_not_bytes(self): | |||||
def test_from_swh_edge_cases_do_no_conversion_if_none_or_not_bytes(): | |||||
some_input = { | some_input = { | ||||
'a': 'something', | 'a': 'something', | ||||
'b': None, | 'b': None, | ||||
'c': 'someone', | 'c': 'someone', | ||||
'd': None, | 'd': None, | ||||
'e': None | 'e': None | ||||
} | } | ||||
expected_output = { | expected_output = { | ||||
'a': 'something', | 'a': 'something', | ||||
'b': None, | 'b': None, | ||||
'c': 'someone', | 'c': 'someone', | ||||
'd': None, | 'd': None, | ||||
'e': None | 'e': None | ||||
} | } | ||||
actual_output = converters.from_swh(some_input, | actual_output = converters.from_swh(some_input, | ||||
hashess={'a', 'b'}, | hashess={'a', 'b'}, | ||||
bytess={'c', 'd'}, | bytess={'c', 'd'}, | ||||
dates={'e'}) | dates={'e'}) | ||||
self.assertEqual(expected_output, actual_output) | assert expected_output == actual_output | ||||
def test_from_swh_edge_cases_convert_invalid_utf8_bytes(self): | def test_from_swh_edge_cases_convert_invalid_utf8_bytes(): | ||||
some_input = { | some_input = { | ||||
'a': 'something', | 'a': 'something', | ||||
'b': 'someone', | 'b': 'someone', | ||||
'c': b'a name \xff', | 'c': b'a name \xff', | ||||
'd': b'an email \xff', | 'd': b'an email \xff', | ||||
} | } | ||||
expected_output = { | expected_output = { | ||||
'a': 'something', | 'a': 'something', | ||||
'b': 'someone', | 'b': 'someone', | ||||
'c': 'a name \\xff', | 'c': 'a name \\xff', | ||||
'd': 'an email \\xff', | 'd': 'an email \\xff', | ||||
'decoding_failures': ['c', 'd'] | 'decoding_failures': ['c', 'd'] | ||||
} | } | ||||
actual_output = converters.from_swh(some_input, | actual_output = converters.from_swh(some_input, | ||||
hashess={'a', 'b'}, | hashess={'a', 'b'}, | ||||
bytess={'c', 'd'}) | bytess={'c', 'd'}) | ||||
for v in ['a', 'b', 'c', 'd']: | for v in ['a', 'b', 'c', 'd']: | ||||
self.assertEqual(expected_output[v], actual_output[v]) | assert expected_output[v] == actual_output[v] | ||||
self.assertEqual(len(expected_output['decoding_failures']), | assert (len(expected_output['decoding_failures']) == | ||||
len(actual_output['decoding_failures'])) | len(actual_output['decoding_failures'])) | ||||
for v in expected_output['decoding_failures']: | for v in expected_output['decoding_failures']: | ||||
self.assertTrue(v in actual_output['decoding_failures']) | assert v in actual_output['decoding_failures'] | ||||
def test_from_swh_empty(self): | def test_from_swh_empty(): | ||||
# when | assert {} == converters.from_swh({}) | ||||
self.assertEqual({}, converters.from_swh({})) | |||||
def test_from_swh_none(self): | |||||
# when | |||||
self.assertIsNone(converters.from_swh(None)) | |||||
def test_from_origin(self): | |||||
# given | def test_from_swh_none(): | ||||
assert converters.from_swh(None) is None | |||||
def test_from_origin(): | |||||
origin_input = { | origin_input = { | ||||
'id': 9, | 'id': 9, | ||||
'type': 'ftp', | 'type': 'ftp', | ||||
'url': 'rsync://ftp.gnu.org/gnu/octave', | 'url': 'rsync://ftp.gnu.org/gnu/octave', | ||||
} | } | ||||
expected_origin = { | expected_origin = { | ||||
'id': 9, | 'id': 9, | ||||
'type': 'ftp', | 'type': 'ftp', | ||||
'url': 'rsync://ftp.gnu.org/gnu/octave', | 'url': 'rsync://ftp.gnu.org/gnu/octave', | ||||
} | } | ||||
# when | |||||
actual_origin = converters.from_origin(origin_input) | actual_origin = converters.from_origin(origin_input) | ||||
# then | assert actual_origin == expected_origin | ||||
self.assertEqual(actual_origin, expected_origin) | |||||
def test_from_origin_visit(self): | |||||
def test_from_origin_visit(): | |||||
snap_hash = 'b5f0b7f716735ebffe38505c60145c4fd9da6ca3' | snap_hash = 'b5f0b7f716735ebffe38505c60145c4fd9da6ca3' | ||||
for snap in [snap_hash, None]: | for snap in [snap_hash, None]: | ||||
# given | |||||
visit = { | visit = { | ||||
'date': { | 'date': { | ||||
'timestamp': datetime.datetime( | 'timestamp': datetime.datetime( | ||||
2015, 1, 1, 22, 0, 0, | 2015, 1, 1, 22, 0, 0, | ||||
tzinfo=datetime.timezone.utc).timestamp(), | tzinfo=datetime.timezone.utc).timestamp(), | ||||
'offset': 0, | 'offset': 0, | ||||
'negative_utc': False, | 'negative_utc': False, | ||||
}, | }, | ||||
'origin': 10, | 'origin': 10, | ||||
'visit': 100, | 'visit': 100, | ||||
'metadata': None, | 'metadata': None, | ||||
'status': 'full', | 'status': 'full', | ||||
'snapshot': hashutil.hash_to_bytes(snap) if snap else snap, | 'snapshot': hashutil.hash_to_bytes(snap) if snap else snap, | ||||
} | } | ||||
expected_visit = { | expected_visit = { | ||||
'date': '2015-01-01T22:00:00+00:00', | 'date': '2015-01-01T22:00:00+00:00', | ||||
'origin': 10, | 'origin': 10, | ||||
'visit': 100, | 'visit': 100, | ||||
'metadata': {}, | 'metadata': {}, | ||||
'status': 'full', | 'status': 'full', | ||||
'snapshot': snap_hash if snap else snap | 'snapshot': snap_hash if snap else snap | ||||
} | } | ||||
# when | |||||
actual_visit = converters.from_origin_visit(visit) | actual_visit = converters.from_origin_visit(visit) | ||||
# then | assert actual_visit == expected_visit | ||||
self.assertEqual(actual_visit, expected_visit) | |||||
def test_from_release(self): | def test_from_release(): | ||||
release_input = { | release_input = { | ||||
'id': hashutil.hash_to_bytes( | 'id': hashutil.hash_to_bytes( | ||||
'aad23fa492a0c5fed0708a6703be875448c86884'), | 'aad23fa492a0c5fed0708a6703be875448c86884'), | ||||
'target': hashutil.hash_to_bytes( | 'target': hashutil.hash_to_bytes( | ||||
'5e46d564378afc44b31bb89f99d5675195fbdf67'), | '5e46d564378afc44b31bb89f99d5675195fbdf67'), | ||||
'target_type': 'revision', | 'target_type': 'revision', | ||||
'date': { | 'date': { | ||||
'timestamp': datetime.datetime( | 'timestamp': datetime.datetime( | ||||
2015, 1, 1, 22, 0, 0, | 2015, 1, 1, 22, 0, 0, | ||||
tzinfo=datetime.timezone.utc).timestamp(), | tzinfo=datetime.timezone.utc).timestamp(), | ||||
'offset': 0, | 'offset': 0, | ||||
'negative_utc': False, | 'negative_utc': False, | ||||
}, | }, | ||||
'author': { | 'author': { | ||||
'name': b'author name', | 'name': b'author name', | ||||
'fullname': b'Author Name author@email', | 'fullname': b'Author Name author@email', | ||||
'email': b'author@email', | 'email': b'author@email', | ||||
}, | }, | ||||
'name': b'v0.0.1', | 'name': b'v0.0.1', | ||||
'message': b'some comment on release', | 'message': b'some comment on release', | ||||
'synthetic': True, | 'synthetic': True, | ||||
} | } | ||||
expected_release = { | expected_release = { | ||||
'id': 'aad23fa492a0c5fed0708a6703be875448c86884', | 'id': 'aad23fa492a0c5fed0708a6703be875448c86884', | ||||
'target': '5e46d564378afc44b31bb89f99d5675195fbdf67', | 'target': '5e46d564378afc44b31bb89f99d5675195fbdf67', | ||||
'target_type': 'revision', | 'target_type': 'revision', | ||||
'date': '2015-01-01T22:00:00+00:00', | 'date': '2015-01-01T22:00:00+00:00', | ||||
'author': { | 'author': { | ||||
'name': 'author name', | 'name': 'author name', | ||||
'fullname': 'Author Name author@email', | 'fullname': 'Author Name author@email', | ||||
'email': 'author@email', | 'email': 'author@email', | ||||
}, | }, | ||||
'name': 'v0.0.1', | 'name': 'v0.0.1', | ||||
'message': 'some comment on release', | 'message': 'some comment on release', | ||||
'target_type': 'revision', | 'target_type': 'revision', | ||||
'synthetic': True, | 'synthetic': True, | ||||
} | } | ||||
# when | |||||
actual_release = converters.from_release(release_input) | actual_release = converters.from_release(release_input) | ||||
# then | assert actual_release == expected_release | ||||
self.assertEqual(actual_release, expected_release) | |||||
def test_from_release_no_revision(self): | |||||
def test_from_release_no_revision(): | |||||
release_input = { | release_input = { | ||||
'id': hashutil.hash_to_bytes( | 'id': hashutil.hash_to_bytes( | ||||
'b2171ee2bdf119cd99a7ec7eff32fa8013ef9a4e'), | 'b2171ee2bdf119cd99a7ec7eff32fa8013ef9a4e'), | ||||
'target': None, | 'target': None, | ||||
'date': { | 'date': { | ||||
'timestamp': datetime.datetime( | 'timestamp': datetime.datetime( | ||||
2016, 3, 2, 10, 0, 0, | 2016, 3, 2, 10, 0, 0, | ||||
tzinfo=datetime.timezone.utc).timestamp(), | tzinfo=datetime.timezone.utc).timestamp(), | ||||
'offset': 0, | 'offset': 0, | ||||
'negative_utc': True, | 'negative_utc': True, | ||||
}, | }, | ||||
'name': b'v0.1.1', | 'name': b'v0.1.1', | ||||
'message': b'comment on release', | 'message': b'comment on release', | ||||
'synthetic': False, | 'synthetic': False, | ||||
'author': { | 'author': { | ||||
'name': b'bob', | 'name': b'bob', | ||||
'fullname': b'Bob bob@alice.net', | 'fullname': b'Bob bob@alice.net', | ||||
'email': b'bob@alice.net', | 'email': b'bob@alice.net', | ||||
}, | }, | ||||
} | } | ||||
expected_release = { | expected_release = { | ||||
'id': 'b2171ee2bdf119cd99a7ec7eff32fa8013ef9a4e', | 'id': 'b2171ee2bdf119cd99a7ec7eff32fa8013ef9a4e', | ||||
'target': None, | 'target': None, | ||||
'date': '2016-03-02T10:00:00-00:00', | 'date': '2016-03-02T10:00:00-00:00', | ||||
'name': 'v0.1.1', | 'name': 'v0.1.1', | ||||
'message': 'comment on release', | 'message': 'comment on release', | ||||
'synthetic': False, | 'synthetic': False, | ||||
'author': { | 'author': { | ||||
'name': 'bob', | 'name': 'bob', | ||||
'fullname': 'Bob bob@alice.net', | 'fullname': 'Bob bob@alice.net', | ||||
'email': 'bob@alice.net', | 'email': 'bob@alice.net', | ||||
}, | }, | ||||
} | } | ||||
# when | |||||
actual_release = converters.from_release(release_input) | actual_release = converters.from_release(release_input) | ||||
# then | assert actual_release == expected_release | ||||
self.assertEqual(actual_release, expected_release) | |||||
def test_from_revision(self): | def test_from_revision(): | ||||
revision_input = { | revision_input = { | ||||
'id': hashutil.hash_to_bytes( | 'id': hashutil.hash_to_bytes( | ||||
'18d8be353ed3480476f032475e7c233eff7371d5'), | '18d8be353ed3480476f032475e7c233eff7371d5'), | ||||
'directory': hashutil.hash_to_bytes( | 'directory': hashutil.hash_to_bytes( | ||||
'7834ef7e7c357ce2af928115c6c6a42b7e2a44e6'), | '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6'), | ||||
'author': { | 'author': { | ||||
'name': b'Software Heritage', | 'name': b'Software Heritage', | ||||
'fullname': b'robot robot@softwareheritage.org', | 'fullname': b'robot robot@softwareheritage.org', | ||||
'email': b'robot@softwareheritage.org', | 'email': b'robot@softwareheritage.org', | ||||
}, | }, | ||||
'committer': { | 'committer': { | ||||
'name': b'Software Heritage', | 'name': b'Software Heritage', | ||||
'fullname': b'robot robot@softwareheritage.org', | 'fullname': b'robot robot@softwareheritage.org', | ||||
'email': b'robot@softwareheritage.org', | 'email': b'robot@softwareheritage.org', | ||||
}, | }, | ||||
'message': b'synthetic revision message', | 'message': b'synthetic revision message', | ||||
'date': { | 'date': { | ||||
'timestamp': datetime.datetime( | 'timestamp': datetime.datetime( | ||||
2000, 1, 17, 11, 23, 54, | 2000, 1, 17, 11, 23, 54, | ||||
tzinfo=datetime.timezone.utc).timestamp(), | tzinfo=datetime.timezone.utc).timestamp(), | ||||
'offset': 0, | 'offset': 0, | ||||
'negative_utc': False, | 'negative_utc': False, | ||||
}, | }, | ||||
'committer_date': { | 'committer_date': { | ||||
'timestamp': datetime.datetime( | 'timestamp': datetime.datetime( | ||||
2000, 1, 17, 11, 23, 54, | 2000, 1, 17, 11, 23, 54, | ||||
tzinfo=datetime.timezone.utc).timestamp(), | tzinfo=datetime.timezone.utc).timestamp(), | ||||
'offset': 0, | 'offset': 0, | ||||
'negative_utc': False, | 'negative_utc': False, | ||||
}, | }, | ||||
'synthetic': True, | 'synthetic': True, | ||||
'type': 'tar', | 'type': 'tar', | ||||
'parents': [ | 'parents': [ | ||||
hashutil.hash_to_bytes( | hashutil.hash_to_bytes( | ||||
'29d8be353ed3480476f032475e7c244eff7371d5'), | '29d8be353ed3480476f032475e7c244eff7371d5'), | ||||
hashutil.hash_to_bytes( | hashutil.hash_to_bytes( | ||||
'30d8be353ed3480476f032475e7c244eff7371d5') | '30d8be353ed3480476f032475e7c244eff7371d5') | ||||
], | ], | ||||
'children': [ | 'children': [ | ||||
hashutil.hash_to_bytes( | hashutil.hash_to_bytes( | ||||
'123546353ed3480476f032475e7c244eff7371d5'), | '123546353ed3480476f032475e7c244eff7371d5'), | ||||
], | ], | ||||
'metadata': { | 'metadata': { | ||||
'extra_headers': [['gpgsig', b'some-signature']], | 'extra_headers': [['gpgsig', b'some-signature']], | ||||
'original_artifact': [{ | 'original_artifact': [{ | ||||
'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', | ||||
}] | }] | ||||
}, | }, | ||||
} | } | ||||
expected_revision = { | expected_revision = { | ||||
'id': '18d8be353ed3480476f032475e7c233eff7371d5', | 'id': '18d8be353ed3480476f032475e7c233eff7371d5', | ||||
'directory': '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6', | 'directory': '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6', | ||||
'author': { | 'author': { | ||||
'name': 'Software Heritage', | 'name': 'Software Heritage', | ||||
'fullname': 'robot robot@softwareheritage.org', | 'fullname': 'robot robot@softwareheritage.org', | ||||
'email': 'robot@softwareheritage.org', | 'email': 'robot@softwareheritage.org', | ||||
}, | }, | ||||
'committer': { | 'committer': { | ||||
'name': 'Software Heritage', | 'name': 'Software Heritage', | ||||
'fullname': 'robot robot@softwareheritage.org', | 'fullname': 'robot robot@softwareheritage.org', | ||||
'email': 'robot@softwareheritage.org', | 'email': 'robot@softwareheritage.org', | ||||
}, | }, | ||||
'message': 'synthetic revision message', | 'message': 'synthetic revision message', | ||||
'date': "2000-01-17T11:23:54+00:00", | 'date': "2000-01-17T11:23:54+00:00", | ||||
'committer_date': "2000-01-17T11:23:54+00:00", | 'committer_date': "2000-01-17T11:23:54+00:00", | ||||
'children': [ | 'children': [ | ||||
'123546353ed3480476f032475e7c244eff7371d5' | '123546353ed3480476f032475e7c244eff7371d5' | ||||
], | ], | ||||
'parents': [ | 'parents': [ | ||||
'29d8be353ed3480476f032475e7c244eff7371d5', | '29d8be353ed3480476f032475e7c244eff7371d5', | ||||
'30d8be353ed3480476f032475e7c244eff7371d5' | '30d8be353ed3480476f032475e7c244eff7371d5' | ||||
], | ], | ||||
'type': 'tar', | 'type': 'tar', | ||||
'synthetic': True, | 'synthetic': True, | ||||
'metadata': { | 'metadata': { | ||||
'extra_headers': [['gpgsig', 'some-signature']], | 'extra_headers': [['gpgsig', 'some-signature']], | ||||
'original_artifact': [{ | 'original_artifact': [{ | ||||
'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 | 'merge': True | ||||
} | } | ||||
# when | |||||
actual_revision = converters.from_revision(revision_input) | actual_revision = converters.from_revision(revision_input) | ||||
# then | assert actual_revision == expected_revision | ||||
self.assertEqual(actual_revision, expected_revision) | |||||
def test_from_revision_nomerge(self): | def test_from_revision_nomerge(): | ||||
revision_input = { | revision_input = { | ||||
'id': hashutil.hash_to_bytes( | 'id': hashutil.hash_to_bytes( | ||||
'18d8be353ed3480476f032475e7c233eff7371d5'), | '18d8be353ed3480476f032475e7c233eff7371d5'), | ||||
'parents': [ | 'parents': [ | ||||
hashutil.hash_to_bytes( | hashutil.hash_to_bytes( | ||||
'29d8be353ed3480476f032475e7c244eff7371d5') | '29d8be353ed3480476f032475e7c244eff7371d5') | ||||
] | ] | ||||
} | } | ||||
expected_revision = { | expected_revision = { | ||||
'id': '18d8be353ed3480476f032475e7c233eff7371d5', | 'id': '18d8be353ed3480476f032475e7c233eff7371d5', | ||||
'parents': [ | 'parents': [ | ||||
'29d8be353ed3480476f032475e7c244eff7371d5' | '29d8be353ed3480476f032475e7c244eff7371d5' | ||||
], | ], | ||||
'merge': False | 'merge': False | ||||
} | } | ||||
# when | |||||
actual_revision = converters.from_revision(revision_input) | actual_revision = converters.from_revision(revision_input) | ||||
# then | assert actual_revision == expected_revision | ||||
self.assertEqual(actual_revision, expected_revision) | |||||
def test_from_revision_noparents(self): | |||||
def test_from_revision_noparents(): | |||||
revision_input = { | revision_input = { | ||||
'id': hashutil.hash_to_bytes( | 'id': hashutil.hash_to_bytes( | ||||
'18d8be353ed3480476f032475e7c233eff7371d5'), | '18d8be353ed3480476f032475e7c233eff7371d5'), | ||||
'directory': hashutil.hash_to_bytes( | 'directory': hashutil.hash_to_bytes( | ||||
'7834ef7e7c357ce2af928115c6c6a42b7e2a44e6'), | '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6'), | ||||
'author': { | 'author': { | ||||
'name': b'Software Heritage', | 'name': b'Software Heritage', | ||||
'fullname': b'robot robot@softwareheritage.org', | 'fullname': b'robot robot@softwareheritage.org', | ||||
'email': b'robot@softwareheritage.org', | 'email': b'robot@softwareheritage.org', | ||||
}, | }, | ||||
'committer': { | 'committer': { | ||||
'name': b'Software Heritage', | 'name': b'Software Heritage', | ||||
'fullname': b'robot robot@softwareheritage.org', | 'fullname': b'robot robot@softwareheritage.org', | ||||
'email': b'robot@softwareheritage.org', | 'email': b'robot@softwareheritage.org', | ||||
}, | }, | ||||
'message': b'synthetic revision message', | 'message': b'synthetic revision message', | ||||
'date': { | 'date': { | ||||
'timestamp': datetime.datetime( | 'timestamp': datetime.datetime( | ||||
2000, 1, 17, 11, 23, 54, | 2000, 1, 17, 11, 23, 54, | ||||
tzinfo=datetime.timezone.utc).timestamp(), | tzinfo=datetime.timezone.utc).timestamp(), | ||||
'offset': 0, | 'offset': 0, | ||||
'negative_utc': False, | 'negative_utc': False, | ||||
}, | }, | ||||
'committer_date': { | 'committer_date': { | ||||
'timestamp': datetime.datetime( | 'timestamp': datetime.datetime( | ||||
2000, 1, 17, 11, 23, 54, | 2000, 1, 17, 11, 23, 54, | ||||
tzinfo=datetime.timezone.utc).timestamp(), | tzinfo=datetime.timezone.utc).timestamp(), | ||||
'offset': 0, | 'offset': 0, | ||||
'negative_utc': False, | 'negative_utc': False, | ||||
}, | }, | ||||
'synthetic': True, | 'synthetic': True, | ||||
'type': 'tar', | 'type': 'tar', | ||||
'children': [ | 'children': [ | ||||
hashutil.hash_to_bytes( | hashutil.hash_to_bytes( | ||||
'123546353ed3480476f032475e7c244eff7371d5'), | '123546353ed3480476f032475e7c244eff7371d5'), | ||||
], | ], | ||||
'metadata': { | 'metadata': { | ||||
'original_artifact': [{ | 'original_artifact': [{ | ||||
'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', | ||||
}] | }] | ||||
}, | }, | ||||
} | } | ||||
expected_revision = { | expected_revision = { | ||||
'id': '18d8be353ed3480476f032475e7c233eff7371d5', | 'id': '18d8be353ed3480476f032475e7c233eff7371d5', | ||||
'directory': '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6', | 'directory': '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6', | ||||
'author': { | 'author': { | ||||
'name': 'Software Heritage', | 'name': 'Software Heritage', | ||||
'fullname': 'robot robot@softwareheritage.org', | 'fullname': 'robot robot@softwareheritage.org', | ||||
'email': 'robot@softwareheritage.org', | 'email': 'robot@softwareheritage.org', | ||||
}, | }, | ||||
'committer': { | 'committer': { | ||||
'name': 'Software Heritage', | 'name': 'Software Heritage', | ||||
'fullname': 'robot robot@softwareheritage.org', | 'fullname': 'robot robot@softwareheritage.org', | ||||
'email': 'robot@softwareheritage.org', | 'email': 'robot@softwareheritage.org', | ||||
}, | }, | ||||
'message': 'synthetic revision message', | 'message': 'synthetic revision message', | ||||
'date': "2000-01-17T11:23:54+00:00", | 'date': "2000-01-17T11:23:54+00:00", | ||||
'committer_date': "2000-01-17T11:23:54+00:00", | 'committer_date': "2000-01-17T11:23:54+00:00", | ||||
'children': [ | 'children': [ | ||||
'123546353ed3480476f032475e7c244eff7371d5' | '123546353ed3480476f032475e7c244eff7371d5' | ||||
], | ], | ||||
'type': 'tar', | 'type': 'tar', | ||||
'synthetic': True, | 'synthetic': True, | ||||
'metadata': { | 'metadata': { | ||||
'original_artifact': [{ | 'original_artifact': [{ | ||||
'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' | ||||
}] | }] | ||||
} | } | ||||
} | } | ||||
# when | |||||
actual_revision = converters.from_revision(revision_input) | actual_revision = converters.from_revision(revision_input) | ||||
# then | assert actual_revision == expected_revision | ||||
self.assertEqual(actual_revision, expected_revision) | |||||
def test_from_revision_invalid(self): | def test_from_revision_invalid(): | ||||
revision_input = { | revision_input = { | ||||
'id': hashutil.hash_to_bytes( | 'id': hashutil.hash_to_bytes( | ||||
'18d8be353ed3480476f032475e7c233eff7371d5'), | '18d8be353ed3480476f032475e7c233eff7371d5'), | ||||
'directory': hashutil.hash_to_bytes( | 'directory': hashutil.hash_to_bytes( | ||||
'7834ef7e7c357ce2af928115c6c6a42b7e2a44e6'), | '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6'), | ||||
'author': { | 'author': { | ||||
'name': b'Software Heritage', | 'name': b'Software Heritage', | ||||
'fullname': b'robot robot@softwareheritage.org', | 'fullname': b'robot robot@softwareheritage.org', | ||||
'email': b'robot@softwareheritage.org', | 'email': b'robot@softwareheritage.org', | ||||
}, | }, | ||||
'committer': { | 'committer': { | ||||
'name': b'Software Heritage', | 'name': b'Software Heritage', | ||||
'fullname': b'robot robot@softwareheritage.org', | 'fullname': b'robot robot@softwareheritage.org', | ||||
'email': b'robot@softwareheritage.org', | 'email': b'robot@softwareheritage.org', | ||||
}, | }, | ||||
'message': b'invalid message \xff', | 'message': b'invalid message \xff', | ||||
'date': { | 'date': { | ||||
'timestamp': datetime.datetime( | 'timestamp': datetime.datetime( | ||||
2000, 1, 17, 11, 23, 54, | 2000, 1, 17, 11, 23, 54, | ||||
tzinfo=datetime.timezone.utc).timestamp(), | tzinfo=datetime.timezone.utc).timestamp(), | ||||
'offset': 0, | 'offset': 0, | ||||
'negative_utc': False, | 'negative_utc': False, | ||||
}, | }, | ||||
'committer_date': { | 'committer_date': { | ||||
'timestamp': datetime.datetime( | 'timestamp': datetime.datetime( | ||||
2000, 1, 17, 11, 23, 54, | 2000, 1, 17, 11, 23, 54, | ||||
tzinfo=datetime.timezone.utc).timestamp(), | tzinfo=datetime.timezone.utc).timestamp(), | ||||
'offset': 0, | 'offset': 0, | ||||
'negative_utc': False, | 'negative_utc': False, | ||||
}, | }, | ||||
'synthetic': True, | 'synthetic': True, | ||||
'type': 'tar', | 'type': 'tar', | ||||
'parents': [ | 'parents': [ | ||||
hashutil.hash_to_bytes( | hashutil.hash_to_bytes( | ||||
'29d8be353ed3480476f032475e7c244eff7371d5'), | '29d8be353ed3480476f032475e7c244eff7371d5'), | ||||
hashutil.hash_to_bytes( | hashutil.hash_to_bytes( | ||||
'30d8be353ed3480476f032475e7c244eff7371d5') | '30d8be353ed3480476f032475e7c244eff7371d5') | ||||
], | ], | ||||
'children': [ | 'children': [ | ||||
hashutil.hash_to_bytes( | hashutil.hash_to_bytes( | ||||
'123546353ed3480476f032475e7c244eff7371d5'), | '123546353ed3480476f032475e7c244eff7371d5'), | ||||
], | ], | ||||
'metadata': { | 'metadata': { | ||||
'original_artifact': [{ | 'original_artifact': [{ | ||||
'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', | ||||
}] | }] | ||||
}, | }, | ||||
} | } | ||||
expected_revision = { | expected_revision = { | ||||
'id': '18d8be353ed3480476f032475e7c233eff7371d5', | 'id': '18d8be353ed3480476f032475e7c233eff7371d5', | ||||
'directory': '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6', | 'directory': '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6', | ||||
'author': { | 'author': { | ||||
'name': 'Software Heritage', | 'name': 'Software Heritage', | ||||
'fullname': 'robot robot@softwareheritage.org', | 'fullname': 'robot robot@softwareheritage.org', | ||||
'email': 'robot@softwareheritage.org', | 'email': 'robot@softwareheritage.org', | ||||
}, | }, | ||||
'committer': { | 'committer': { | ||||
'name': 'Software Heritage', | 'name': 'Software Heritage', | ||||
'fullname': 'robot robot@softwareheritage.org', | 'fullname': 'robot robot@softwareheritage.org', | ||||
'email': 'robot@softwareheritage.org', | 'email': 'robot@softwareheritage.org', | ||||
}, | }, | ||||
'message': None, | 'message': None, | ||||
'message_decoding_failed': True, | 'message_decoding_failed': True, | ||||
'date': "2000-01-17T11:23:54+00:00", | 'date': "2000-01-17T11:23:54+00:00", | ||||
'committer_date': "2000-01-17T11:23:54+00:00", | 'committer_date': "2000-01-17T11:23:54+00:00", | ||||
'children': [ | 'children': [ | ||||
'123546353ed3480476f032475e7c244eff7371d5' | '123546353ed3480476f032475e7c244eff7371d5' | ||||
], | ], | ||||
'parents': [ | 'parents': [ | ||||
'29d8be353ed3480476f032475e7c244eff7371d5', | '29d8be353ed3480476f032475e7c244eff7371d5', | ||||
'30d8be353ed3480476f032475e7c244eff7371d5' | '30d8be353ed3480476f032475e7c244eff7371d5' | ||||
], | ], | ||||
'type': 'tar', | 'type': 'tar', | ||||
'synthetic': True, | 'synthetic': True, | ||||
'metadata': { | 'metadata': { | ||||
'original_artifact': [{ | 'original_artifact': [{ | ||||
'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 | 'merge': True | ||||
} | } | ||||
# when | |||||
actual_revision = converters.from_revision(revision_input) | actual_revision = converters.from_revision(revision_input) | ||||
# then | assert actual_revision == expected_revision | ||||
self.assertEqual(actual_revision, expected_revision) | |||||
def test_from_content_none(self): | |||||
self.assertIsNone(converters.from_content(None)) | |||||
def test_from_content(self): | def test_from_content_none(): | ||||
assert converters.from_content(None) is None | |||||
def test_from_content(): | |||||
content_input = { | content_input = { | ||||
'sha1': hashutil.hash_to_bytes( | 'sha1': hashutil.hash_to_bytes( | ||||
'5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5'), | '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5'), | ||||
'sha256': hashutil.hash_to_bytes( | 'sha256': hashutil.hash_to_bytes( | ||||
'39007420ca5de7cb3cfc15196335507e' | '39007420ca5de7cb3cfc15196335507e' | ||||
'e76c98930e7e0afa4d2747d3bf96c926'), | 'e76c98930e7e0afa4d2747d3bf96c926'), | ||||
'blake2s256': hashutil.hash_to_bytes( | 'blake2s256': hashutil.hash_to_bytes( | ||||
'49007420ca5de7cb3cfc15196335507e' | '49007420ca5de7cb3cfc15196335507e' | ||||
'e76c98930e7e0afa4d2747d3bf96c926'), | 'e76c98930e7e0afa4d2747d3bf96c926'), | ||||
'sha1_git': hashutil.hash_to_bytes( | 'sha1_git': hashutil.hash_to_bytes( | ||||
'40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03'), | '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03'), | ||||
'ctime': 'something-which-is-filtered-out', | 'ctime': 'something-which-is-filtered-out', | ||||
'data': b'data in bytes', | 'data': b'data in bytes', | ||||
'length': 10, | 'length': 10, | ||||
'status': 'hidden', | 'status': 'hidden', | ||||
} | } | ||||
# 'status' is filtered | # 'status' is filtered | ||||
expected_content = { | expected_content = { | ||||
'checksums': { | 'checksums': { | ||||
'sha1': '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5', | 'sha1': '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5', | ||||
'sha256': '39007420ca5de7cb3cfc15196335507ee76c98' | 'sha256': '39007420ca5de7cb3cfc15196335507ee76c98' | ||||
'930e7e0afa4d2747d3bf96c926', | '930e7e0afa4d2747d3bf96c926', | ||||
'blake2s256': '49007420ca5de7cb3cfc15196335507ee7' | 'blake2s256': '49007420ca5de7cb3cfc15196335507ee7' | ||||
'6c98930e7e0afa4d2747d3bf96c926', | '6c98930e7e0afa4d2747d3bf96c926', | ||||
'sha1_git': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', | 'sha1_git': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', | ||||
}, | }, | ||||
'data': b'data in bytes', | 'data': b'data in bytes', | ||||
'length': 10, | 'length': 10, | ||||
'status': 'absent', | 'status': 'absent', | ||||
} | } | ||||
# when | |||||
actual_content = converters.from_content(content_input) | actual_content = converters.from_content(content_input) | ||||
# then | assert actual_content == expected_content | ||||
self.assertEqual(actual_content, expected_content) | |||||
def test_from_person(self): | def test_from_person(): | ||||
person_input = { | person_input = { | ||||
'id': 10, | 'id': 10, | ||||
'anything': 'else', | 'anything': 'else', | ||||
'name': b'bob', | 'name': b'bob', | ||||
'fullname': b'bob bob@alice.net', | 'fullname': b'bob bob@alice.net', | ||||
'email': b'bob@foo.alice', | 'email': b'bob@foo.alice', | ||||
} | } | ||||
expected_person = { | expected_person = { | ||||
'id': 10, | 'id': 10, | ||||
'anything': 'else', | 'anything': 'else', | ||||
'name': 'bob', | 'name': 'bob', | ||||
'fullname': 'bob bob@alice.net', | 'fullname': 'bob bob@alice.net', | ||||
'email': 'bob@foo.alice', | 'email': 'bob@foo.alice', | ||||
} | } | ||||
# when | |||||
actual_person = converters.from_person(person_input) | actual_person = converters.from_person(person_input) | ||||
# then | assert actual_person == expected_person | ||||
self.assertEqual(actual_person, expected_person) | |||||
def test_from_directory_entries(self): | |||||
def test_from_directory_entries(): | |||||
dir_entries_input = { | dir_entries_input = { | ||||
'sha1': hashutil.hash_to_bytes( | 'sha1': hashutil.hash_to_bytes( | ||||
'5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5'), | '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5'), | ||||
'sha256': hashutil.hash_to_bytes( | 'sha256': hashutil.hash_to_bytes( | ||||
'39007420ca5de7cb3cfc15196335507e' | '39007420ca5de7cb3cfc15196335507e' | ||||
'e76c98930e7e0afa4d2747d3bf96c926'), | 'e76c98930e7e0afa4d2747d3bf96c926'), | ||||
'sha1_git': hashutil.hash_to_bytes( | 'sha1_git': hashutil.hash_to_bytes( | ||||
'40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03'), | '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03'), | ||||
'blake2s256': hashutil.hash_to_bytes( | 'blake2s256': hashutil.hash_to_bytes( | ||||
'685395c5dc57cada459364f0946d3dd45bad5fcbab' | '685395c5dc57cada459364f0946d3dd45bad5fcbab' | ||||
'c1048edb44380f1d31d0aa'), | 'c1048edb44380f1d31d0aa'), | ||||
'target': hashutil.hash_to_bytes( | 'target': hashutil.hash_to_bytes( | ||||
'40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03'), | '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03'), | ||||
'dir_id': hashutil.hash_to_bytes( | 'dir_id': hashutil.hash_to_bytes( | ||||
'40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03'), | '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03'), | ||||
'name': b'bob', | 'name': b'bob', | ||||
'type': 10, | 'type': 10, | ||||
'status': 'hidden', | 'status': 'hidden', | ||||
} | } | ||||
expected_dir_entries = { | expected_dir_entries = { | ||||
'checksums': { | 'checksums': { | ||||
'sha1': '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5', | 'sha1': '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5', | ||||
'sha256': '39007420ca5de7cb3cfc15196335507ee76c98' | 'sha256': '39007420ca5de7cb3cfc15196335507ee76c98' | ||||
'930e7e0afa4d2747d3bf96c926', | '930e7e0afa4d2747d3bf96c926', | ||||
'sha1_git': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', | 'sha1_git': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', | ||||
'blake2s256': '685395c5dc57cada459364f0946d3dd45bad5f' | 'blake2s256': '685395c5dc57cada459364f0946d3dd45bad5f' | ||||
'cbabc1048edb44380f1d31d0aa', | 'cbabc1048edb44380f1d31d0aa', | ||||
}, | }, | ||||
'target': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', | 'target': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', | ||||
'dir_id': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', | 'dir_id': '40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03', | ||||
'name': 'bob', | 'name': 'bob', | ||||
'type': 10, | 'type': 10, | ||||
'status': 'absent', | 'status': 'absent', | ||||
} | } | ||||
# when | |||||
actual_dir_entries = converters.from_directory_entry(dir_entries_input) | actual_dir_entries = converters.from_directory_entry(dir_entries_input) | ||||
# then | assert actual_dir_entries == expected_dir_entries | ||||
self.assertEqual(actual_dir_entries, expected_dir_entries) | |||||
def test_from_filetype(self): | def test_from_filetype(): | ||||
content_filetype = { | content_filetype = { | ||||
'id': hashutil.hash_to_bytes( | 'id': hashutil.hash_to_bytes( | ||||
'5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5'), | '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5'), | ||||
'encoding': 'utf-8', | 'encoding': 'utf-8', | ||||
'mimetype': 'text/plain', | 'mimetype': 'text/plain', | ||||
} | } | ||||
expected_content_filetype = { | expected_content_filetype = { | ||||
'id': '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5', | 'id': '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5', | ||||
'encoding': 'utf-8', | 'encoding': 'utf-8', | ||||
'mimetype': 'text/plain', | 'mimetype': 'text/plain', | ||||
} | } | ||||
# when | |||||
actual_content_filetype = converters.from_filetype(content_filetype) | actual_content_filetype = converters.from_filetype(content_filetype) | ||||
# then | assert actual_content_filetype == expected_content_filetype | ||||
self.assertEqual(actual_content_filetype, expected_content_filetype) |