Skip to content
Snippets Groups Projects
Commit ed4e96bd authored by vlorentz's avatar vlorentz
Browse files

Start removing mocks for the mimetype indexer.

parent c2db7446
No related branches found
No related tags found
1 merge request!69Start removing mocks for the mimetype indexer.
...@@ -102,10 +102,62 @@ class IndexerStorage: ...@@ -102,10 +102,62 @@ class IndexerStorage:
def __init__(self): def __init__(self):
self._tools = {} self._tools = {}
self._mimetypes = SubStorage(self._tools)
self._content_ctags = SubStorage(self._tools) self._content_ctags = SubStorage(self._tools)
self._content_metadata = SubStorage(self._tools) self._content_metadata = SubStorage(self._tools)
self._revision_metadata = SubStorage(self._tools) self._revision_metadata = SubStorage(self._tools)
def content_mimetype_missing(self, mimetypes):
"""Generate mimetypes missing from storage.
Args:
mimetypes (iterable): iterable of dict with keys:
- **id** (bytes): sha1 identifier
- **indexer_configuration_id** (int): tool used to compute the
results
Yields:
tuple (id, indexer_configuration_id): missing id
"""
yield from self._mimetypes.missing(mimetypes)
def content_mimetype_add(self, mimetypes, conflict_update=False):
"""Add mimetypes not present in storage.
Args:
mimetypes (iterable): dictionaries with keys:
- **id** (bytes): sha1 identifier
- **mimetype** (bytes): raw content's mimetype
- **encoding** (bytes): raw content's encoding
- **indexer_configuration_id** (int): tool's id used to
compute the results
- **conflict_update** (bool): Flag to determine if we want to
overwrite (``True``) or skip duplicates (``False``, the
default)
"""
self._mimetypes.add(mimetypes, conflict_update)
def content_mimetype_get(self, ids, db=None, cur=None):
"""Retrieve full content mimetype per ids.
Args:
ids (iterable): sha1 identifier
Yields:
mimetypes (iterable): dictionaries with keys:
- **id** (bytes): sha1 identifier
- **mimetype** (bytes): raw content's mimetype
- **encoding** (bytes): raw content's encoding
- **tool** (dict): Tool used to compute the language
"""
yield from self._mimetypes.get(ids)
def content_ctags_missing(self, ctags): def content_ctags_missing(self, ctags):
"""List ctags missing from storage. """List ctags missing from storage.
......
...@@ -17,22 +17,6 @@ class IndexerTestInMemoryStorage(CommonTestStorage, TestCase): ...@@ -17,22 +17,6 @@ class IndexerTestInMemoryStorage(CommonTestStorage, TestCase):
def test_check_config(self): def test_check_config(self):
pass pass
@pytest.mark.xfail
def test_content_mimetype_missing(self):
pass
@pytest.mark.xfail
def test_content_mimetype_add__drop_duplicate(self):
pass
@pytest.mark.xfail
def test_content_mimetype_add__update_in_place_duplicate(self):
pass
@pytest.mark.xfail
def test_content_mimetype_get(self):
pass
@pytest.mark.xfail @pytest.mark.xfail
def test_content_language_missing(self): def test_content_language_missing(self):
pass pass
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
# See top-level LICENSE file for more information # See top-level LICENSE file for more information
import unittest import unittest
import logging
from unittest.mock import patch from unittest.mock import patch
...@@ -61,12 +60,6 @@ class MimetypeTestIndexer(MimetypeIndexer): ...@@ -61,12 +60,6 @@ class MimetypeTestIndexer(MimetypeIndexer):
}, },
} }
def prepare(self):
super().prepare()
self.idx_storage = BasicMockIndexerStorage()
self.log = logging.getLogger('swh.indexer')
self.objstorage = MockObjStorage()
class TestMimetypeIndexer(CommonContentIndexerTest, unittest.TestCase): class TestMimetypeIndexer(CommonContentIndexerTest, unittest.TestCase):
"""Mimetype indexer test scenarios: """Mimetype indexer test scenarios:
...@@ -75,8 +68,13 @@ class TestMimetypeIndexer(CommonContentIndexerTest, unittest.TestCase): ...@@ -75,8 +68,13 @@ class TestMimetypeIndexer(CommonContentIndexerTest, unittest.TestCase):
- Unknown sha1 in the input list are not indexed - Unknown sha1 in the input list are not indexed
""" """
def get_indexer_results(self, ids):
yield from self.idx_storage.content_mimetype_get(ids)
def setUp(self): def setUp(self):
self.indexer = MimetypeTestIndexer() self.indexer = MimetypeTestIndexer()
self.idx_storage = self.indexer.idx_storage
self.id0 = '01c9379dfc33803963d07c1ccc748d3fe4c96bb5' self.id0 = '01c9379dfc33803963d07c1ccc748d3fe4c96bb5'
self.id1 = '688a5ef812c53907562fe379d4b3851e69c7cb15' self.id1 = '688a5ef812c53907562fe379d4b3851e69c7cb15'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment