mirror of
https://github.com/Hopiu/xapian-haystack.git
synced 2026-04-25 09:04:50 +00:00
Fixed tests for Django 1.7 and 1.8.
This commit is contained in:
parent
89f05790b1
commit
767458509c
5 changed files with 26 additions and 17 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import os
|
||||
from settings import *
|
||||
|
||||
INSTALLED_APPS += [
|
||||
'xapian_tests',
|
||||
INSTALLED_APPS = [
|
||||
'test_haystack.core',
|
||||
'test_haystack.xapian_tests',
|
||||
]
|
||||
|
||||
HAYSTACK_CONNECTIONS = {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from haystack import indexes
|
|||
from . import models
|
||||
|
||||
|
||||
class DocumentIndex(indexes.SearchIndex):
|
||||
class DocumentIndex(indexes.SearchIndex, indexes.Indexable):
|
||||
text = indexes.CharField(document=True)
|
||||
summary = indexes.CharField(model_attr='summary')
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ class DocumentIndex(indexes.SearchIndex):
|
|||
tags = indexes.MultiValueField()
|
||||
|
||||
def get_model(self):
|
||||
return models.Document()
|
||||
return models.Document
|
||||
|
||||
def prepare_tags(self, obj):
|
||||
l = [['tag', 'tag-test', 'tag-test-test'],
|
||||
|
|
|
|||
|
|
@ -8,14 +8,21 @@ import os
|
|||
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
from django.db.models.loading import get_model
|
||||
|
||||
from haystack import connections
|
||||
from haystack import indexes
|
||||
from haystack.backends.xapian_backend import InvalidIndexError, _term_to_xapian_value
|
||||
from haystack.models import SearchResult
|
||||
from haystack.utils.loading import UnifiedIndex
|
||||
|
||||
from core.models import MockTag, MockModel, AnotherMockModel
|
||||
from mocks import MockSearchResult
|
||||
from ...core.models import AnotherMockModel, MockTag
|
||||
|
||||
|
||||
class XapianMockSearchResult(SearchResult):
|
||||
def __init__(self, app_label, model_name, pk, score, **kwargs):
|
||||
super(XapianMockSearchResult, self).__init__(app_label, model_name, pk, score, **kwargs)
|
||||
self._model = get_model('xapian_tests', model_name)
|
||||
|
||||
|
||||
def get_terms(backend, *args):
|
||||
|
|
@ -435,8 +442,9 @@ class BackendFeaturesTestCase(HaystackBackendTestCase, TestCase):
|
|||
[1, 2, 3])
|
||||
|
||||
# Other `result_class`
|
||||
self.assertTrue(isinstance(self.backend.search(xapian.Query('indexed'),
|
||||
result_class=MockSearchResult)['results'][0], MockSearchResult))
|
||||
self.assertTrue(
|
||||
isinstance(self.backend.search(xapian.Query('indexed'), result_class=XapianMockSearchResult)['results'][0],
|
||||
XapianMockSearchResult))
|
||||
|
||||
def test_search_field_with_punctuation(self):
|
||||
self.assertEqual(pks(self.backend.search(xapian.Query('http://example.com/1/'))['results']),
|
||||
|
|
@ -559,9 +567,9 @@ class BackendFeaturesTestCase(HaystackBackendTestCase, TestCase):
|
|||
self.assertEqual(pks(results['results']), [3, 2])
|
||||
|
||||
# Other `result_class`
|
||||
self.assertTrue(isinstance(self.backend.more_like_this(self.sample_objs[0],
|
||||
result_class=MockSearchResult)['results'][0],
|
||||
MockSearchResult))
|
||||
result = self.backend.more_like_this(self.sample_objs[0],
|
||||
result_class=XapianMockSearchResult)
|
||||
self.assertTrue(isinstance(result['results'][0], XapianMockSearchResult))
|
||||
|
||||
def test_order_by(self):
|
||||
results = self.backend.search(xapian.Query(''), sort_by=['pub_date'])
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ from haystack import connections
|
|||
from haystack.inputs import AutoQuery
|
||||
from haystack.query import SearchQuerySet
|
||||
|
||||
from xapian_tests.models import Document
|
||||
from xapian_tests.search_indexes import DocumentIndex
|
||||
from xapian_tests.tests.test_backend import pks, get_terms
|
||||
from ..models import Document
|
||||
from ..search_indexes import DocumentIndex
|
||||
from ..tests.test_backend import pks, get_terms
|
||||
|
||||
|
||||
class InterfaceTestCase(TestCase):
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ from haystack import connections, reset_search_queries
|
|||
from haystack.models import SearchResult
|
||||
from haystack.query import SearchQuerySet, SQ
|
||||
|
||||
from core.models import MockModel, AnotherMockModel, AFourthMockModel
|
||||
from mocks import MockSearchResult
|
||||
from xapian_tests.tests.test_backend import HaystackBackendTestCase
|
||||
from ...core.models import MockModel, AnotherMockModel, AFourthMockModel
|
||||
from ...mocks import MockSearchResult
|
||||
from ..tests.test_backend import HaystackBackendTestCase
|
||||
|
||||
|
||||
class MockQueryIndex(indexes.SearchIndex):
|
||||
|
|
|
|||
Loading…
Reference in a new issue