Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_mimetype.py
Show All 9 Lines | |||||
from swh.indexer.mimetype import ( | from swh.indexer.mimetype import ( | ||||
ContentMimetypeIndexer, MimetypeRangeIndexer, compute_mimetype_encoding | ContentMimetypeIndexer, MimetypeRangeIndexer, compute_mimetype_encoding | ||||
) | ) | ||||
from swh.indexer.tests.test_utils import ( | from swh.indexer.tests.test_utils import ( | ||||
MockObjStorage, BasicMockStorage, BasicMockIndexerStorage, | MockObjStorage, BasicMockStorage, BasicMockIndexerStorage, | ||||
CommonContentIndexerTest, CommonContentIndexerRangeTest, | CommonContentIndexerTest, CommonContentIndexerRangeTest, | ||||
CommonIndexerWithErrorsTest, CommonIndexerNoTool | CommonIndexerWithErrorsTest, CommonIndexerNoTool, | ||||
BASE_TEST_CONFIG | |||||
) | ) | ||||
class FakeMagicResult: | class FakeMagicResult: | ||||
def __init__(self, mimetype, encoding): | def __init__(self, mimetype, encoding): | ||||
self.mime_type = mimetype | self.mime_type = mimetype | ||||
self.encoding = encoding | self.encoding = encoding | ||||
Show All 15 Lines | def test_compute_mimetype_encoding(self, mock_magic): | ||||
}) | }) | ||||
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. | ||||
""" | """ | ||||
def prepare(self): | def parse_config_file(self, *args, **kwargs): | ||||
self.config = { | return { | ||||
**BASE_TEST_CONFIG, | |||||
'tools': { | 'tools': { | ||||
'name': 'file', | 'name': 'file', | ||||
'version': '1:5.30-1+deb9u1', | 'version': '1:5.30-1+deb9u1', | ||||
'configuration': { | 'configuration': { | ||||
"type": "library", | "type": "library", | ||||
"debian-package": "python3-magic" | "debian-package": "python3-magic" | ||||
}, | }, | ||||
}, | }, | ||||
} | } | ||||
def prepare(self): | |||||
super().prepare() | |||||
self.idx_storage = BasicMockIndexerStorage() | self.idx_storage = BasicMockIndexerStorage() | ||||
self.log = logging.getLogger('swh.indexer') | self.log = logging.getLogger('swh.indexer') | ||||
self.objstorage = MockObjStorage() | self.objstorage = MockObjStorage() | ||||
self.tools = self.register_tools(self.config['tools']) | |||||
self.tool = self.tools[0] | |||||
class TestMimetypeIndexer(CommonContentIndexerTest, unittest.TestCase): | class TestMimetypeIndexer(CommonContentIndexerTest, unittest.TestCase): | ||||
"""Mimetype indexer test scenarios: | """Mimetype indexer test scenarios: | ||||
- Known sha1s in the input list have their data indexed | - Known sha1s in the input list have their data indexed | ||||
- Unknown sha1 in the input list are not indexed | - Unknown sha1 in the input list are not indexed | ||||
Show All 27 Lines | def setUp(self): | ||||
} | } | ||||
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. | ||||
""" | """ | ||||
def prepare(self): | def parse_config_file(self, *args, **kwargs): | ||||
self.config = { | return { | ||||
**BASE_TEST_CONFIG, | |||||
'tools': { | 'tools': { | ||||
'name': 'file', | 'name': 'file', | ||||
'version': '1:5.30-1+deb9u1', | 'version': '1:5.30-1+deb9u1', | ||||
'configuration': { | 'configuration': { | ||||
"type": "library", | "type": "library", | ||||
"debian-package": "python3-magic" | "debian-package": "python3-magic" | ||||
}, | }, | ||||
}, | }, | ||||
'write_batch_size': 100, | 'write_batch_size': 100, | ||||
} | } | ||||
def prepare(self): | |||||
super().prepare() | |||||
self.idx_storage = BasicMockIndexerStorage() | self.idx_storage = BasicMockIndexerStorage() | ||||
self.log = logging.getLogger('swh.indexer') | |||||
# this hardcodes some contents, will use this to setup the storage | # this hardcodes some contents, will use this to setup the storage | ||||
self.objstorage = MockObjStorage() | self.objstorage = MockObjStorage() | ||||
# sync objstorage and storage | # sync objstorage and storage | ||||
contents = [{'sha1': c_id} for c_id in self.objstorage] | contents = [{'sha1': c_id} for c_id in self.objstorage] | ||||
self.storage = BasicMockStorage(contents) | self.storage = BasicMockStorage(contents) | ||||
self.tools = self.register_tools(self.config['tools']) | |||||
self.tool = self.tools[0] | |||||
class TestMimetypeRangeIndexer( | class TestMimetypeRangeIndexer( | ||||
CommonContentIndexerRangeTest, unittest.TestCase): | CommonContentIndexerRangeTest, unittest.TestCase): | ||||
"""Range Mimetype Indexer tests. | """Range Mimetype Indexer tests. | ||||
- new data within range are indexed | - new data within range are indexed | ||||
- no data outside a range are indexed | - no data outside a range are indexed | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |