Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_mimetype.py
Show All 31 Lines | def test_compute_mimetype_encoding(self, mock_magic): | ||||
for _input, _mimetype, _encoding in [ | for _input, _mimetype, _encoding in [ | ||||
(b'some-content', 'text/plain', 'utf-8'), | (b'some-content', 'text/plain', 'utf-8'), | ||||
(b'raw-content', 'application/json', 'ascii')]: | (b'raw-content', 'application/json', 'ascii')]: | ||||
mock_magic.detect_from_content.return_value = FakeMagicResult( | mock_magic.detect_from_content.return_value = FakeMagicResult( | ||||
_mimetype, _encoding) | _mimetype, _encoding) | ||||
actual_result = compute_mimetype_encoding(_input) | actual_result = compute_mimetype_encoding(_input) | ||||
self.assertEqual(actual_result, { | self.assertEqual(actual_result, { | ||||
'mimetype': _mimetype.encode('utf-8'), | 'mimetype': _mimetype, | ||||
'encoding': _encoding.encode('utf-8'), | 'encoding': _encoding | ||||
}) | }) | ||||
class MimetypeTestIndexer(ContentMimetypeIndexer): | class MimetypeTestIndexer(ContentMimetypeIndexer): | ||||
"""Specific mimetype indexer instance whose configuration is enough to | """Specific mimetype indexer instance whose configuration is enough to | ||||
satisfy the indexing tests. | satisfy the indexing tests. | ||||
""" | """ | ||||
Show All 28 Lines | def setUp(self): | ||||
self.id0 = '01c9379dfc33803963d07c1ccc748d3fe4c96bb5' | self.id0 = '01c9379dfc33803963d07c1ccc748d3fe4c96bb5' | ||||
self.id1 = '688a5ef812c53907562fe379d4b3851e69c7cb15' | self.id1 = '688a5ef812c53907562fe379d4b3851e69c7cb15' | ||||
self.id2 = 'da39a3ee5e6b4b0d3255bfef95601890afd80709' | self.id2 = 'da39a3ee5e6b4b0d3255bfef95601890afd80709' | ||||
tool_id = self.indexer.tool['id'] | tool_id = self.indexer.tool['id'] | ||||
self.expected_results = { | self.expected_results = { | ||||
self.id0: { | self.id0: { | ||||
'id': self.id0, | 'id': self.id0, | ||||
'indexer_configuration_id': tool_id, | 'indexer_configuration_id': tool_id, | ||||
'mimetype': b'text/plain', | 'mimetype': 'text/plain', | ||||
'encoding': b'us-ascii', | 'encoding': 'us-ascii', | ||||
}, | }, | ||||
self.id1: { | self.id1: { | ||||
'id': self.id1, | 'id': self.id1, | ||||
'indexer_configuration_id': tool_id, | 'indexer_configuration_id': tool_id, | ||||
'mimetype': b'text/plain', | 'mimetype': 'text/plain', | ||||
'encoding': b'us-ascii', | 'encoding': 'us-ascii', | ||||
}, | }, | ||||
self.id2: { | self.id2: { | ||||
'id': self.id2, | 'id': self.id2, | ||||
'indexer_configuration_id': tool_id, | 'indexer_configuration_id': tool_id, | ||||
'mimetype': b'application/x-empty', | 'mimetype': 'application/x-empty', | ||||
'encoding': b'binary', | 'encoding': 'binary', | ||||
} | } | ||||
} | } | ||||
class MimetypeRangeIndexerTest(MimetypeRangeIndexer): | class MimetypeRangeIndexerTest(MimetypeRangeIndexer): | ||||
"""Specific mimetype whose configuration is enough to satisfy the | """Specific mimetype whose configuration is enough to satisfy the | ||||
indexing tests. | indexing tests. | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | def setUp(self): | ||||
self.id0 = '01c9379dfc33803963d07c1ccc748d3fe4c96bb5' | self.id0 = '01c9379dfc33803963d07c1ccc748d3fe4c96bb5' | ||||
self.id1 = '02fb2c89e14f7fab46701478c83779c7beb7b069' | self.id1 = '02fb2c89e14f7fab46701478c83779c7beb7b069' | ||||
self.id2 = '103bc087db1d26afc3a0283f38663d081e9b01e6' | self.id2 = '103bc087db1d26afc3a0283f38663d081e9b01e6' | ||||
tool_id = self.indexer.tool['id'] | tool_id = self.indexer.tool['id'] | ||||
self.expected_results = { | self.expected_results = { | ||||
self.id0: { | self.id0: { | ||||
'encoding': b'us-ascii', | 'encoding': 'us-ascii', | ||||
'id': self.id0, | 'id': self.id0, | ||||
'indexer_configuration_id': tool_id, | 'indexer_configuration_id': tool_id, | ||||
'mimetype': b'text/plain'}, | 'mimetype': 'text/plain'}, | ||||
self.id1: { | self.id1: { | ||||
'encoding': b'us-ascii', | 'encoding': 'us-ascii', | ||||
'id': self.id1, | 'id': self.id1, | ||||
'indexer_configuration_id': tool_id, | 'indexer_configuration_id': tool_id, | ||||
'mimetype': b'text/x-python'}, | 'mimetype': 'text/x-python'}, | ||||
self.id2: { | self.id2: { | ||||
'encoding': b'us-ascii', | 'encoding': 'us-ascii', | ||||
'id': self.id2, | 'id': self.id2, | ||||
'indexer_configuration_id': tool_id, | 'indexer_configuration_id': tool_id, | ||||
'mimetype': b'text/plain'} | 'mimetype': 'text/plain'} | ||||
} | } | ||||
class MimetypeIndexerUnknownToolTestStorage( | class MimetypeIndexerUnknownToolTestStorage( | ||||
CommonIndexerNoTool, MimetypeTestIndexer): | CommonIndexerNoTool, MimetypeTestIndexer): | ||||
"""Mimetype indexer with wrong configuration""" | """Mimetype indexer with wrong configuration""" | ||||
Show All 10 Lines |