Commit 2eff9cdc by Oleg Marshev

Add some mapping type tests.

parent 5d4a23ac
...@@ -82,6 +82,10 @@ def delete_in_index(sender, instance, **kwargs): ...@@ -82,6 +82,10 @@ def delete_in_index(sender, instance, **kwargs):
class NoteMappingType(MappingType, Indexable): class NoteMappingType(MappingType, Indexable):
"""
Mapping type for Note.
"""
@classmethod @classmethod
def get_model(cls): def get_model(cls):
return Note return Note
...@@ -107,7 +111,9 @@ class NoteMappingType(MappingType, Indexable): ...@@ -107,7 +111,9 @@ class NoteMappingType(MappingType, Indexable):
@classmethod @classmethod
def extract_document(cls, obj_id, obj=None): def extract_document(cls, obj_id, obj=None):
"""Converts this instance into an Elasticsearch document""" """
Converts this instance into an Elasticsearch document.
"""
if obj is None: if obj is None:
obj = cls.get_model().objects.get(pk=obj_id) obj = cls.get_model().objects.get(pk=obj_id)
...@@ -115,6 +121,11 @@ class NoteMappingType(MappingType, Indexable): ...@@ -115,6 +121,11 @@ class NoteMappingType(MappingType, Indexable):
@staticmethod @staticmethod
def process_result(data): def process_result(data):
"""
Prepares result for response.
Also prepares ranges field and highlighting.
"""
for i, item in enumerate(data): for i, item in enumerate(data):
if isinstance(item, dict): if isinstance(item, dict):
for k, v in item.items(): for k, v in item.items():
......
...@@ -58,3 +58,21 @@ class NoteTest(TestCase): ...@@ -58,3 +58,21 @@ class NoteTest(TestCase):
note.clean(self.note) note.clean(self.note)
note.save() note.save()
self.assertEqual(NoteMappingType.extract_document(note.id), note.as_dict()) self.assertEqual(NoteMappingType.extract_document(note.id), note.as_dict())
def test_get_model(self):
self.assertIsInstance(NoteMappingType.get_model()(), Note)
def test_get_mapping(self):
expected_mapping = {
'properties': {
'id': {'type': 'string', 'index': 'not_analyzed', 'store': True},
'user': {'type': 'string', 'index': 'not_analyzed', 'store': True},
'course_id': {'type': 'string', 'index': 'not_analyzed', 'store': True},
'usage_id': {'type': 'string', 'index': 'not_analyzed', 'store': True},
'text': {'type': 'string', 'analyzer': 'snowball', 'store': True},
'quote': {'type': 'string', 'analyzer': 'snowball', 'store': True},
'created': {'type': 'date', 'store': True},
'updated': {'type': 'date', 'store': True},
}
}
self.assertEqual(NoteMappingType.get_mapping(), expected_mapping)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment