Skip to content

Commit abb420d

Browse files
committed
Tests: avoid side effects from build_schema_wrong_backend test
Previously, this would pollute the global settings for the Whoosh backend causing a failure if the Solr tests ran first. Now this uses mock.patch which cleans up after itself automatically and makes the intention of the code immediately obvious
1 parent f32faf4 commit abb420d

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

test_haystack/solr_tests/test_management_commands.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import datetime
2-
3-
from mock import patch
4-
import pysolr
52
from tempfile import mkdtemp
63

4+
import pysolr
75
from django import VERSION as DJANGO_VERSION
86
from django.conf import settings
97
from django.core.exceptions import ImproperlyConfigured
108
from django.core.management import call_command
119
from django.test import TestCase
1210
from django.utils import unittest
11+
from mock import patch
1312

14-
from haystack import connections
15-
from haystack import indexes
13+
from haystack import connections, indexes
1614
from haystack.utils.loading import UnifiedIndex
1715

1816
from ..core.models import MockModel, MockTag
@@ -145,13 +143,11 @@ def test_multiprocessing(self):
145143
call_command('update_index', verbosity=2, workers=2, batchsize=5)
146144
self.assertEqual(self.solr.search('*:*').hits, 23)
147145

146+
@patch.dict(settings.HAYSTACK_CONNECTIONS['whoosh'], {'PATH': mkdtemp(prefix='dummy-path-')})
148147
def test_build_schema_wrong_backend(self):
149-
150-
settings.HAYSTACK_CONNECTIONS['whoosh'] = {'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
151-
'PATH': mkdtemp(prefix='dummy-path-'),}
152-
153148
connections['whoosh']._index = self.ui
154-
self.assertRaises(ImproperlyConfigured, call_command, 'build_solr_schema',using='whoosh', interactive=False)
149+
self.assertRaises(ImproperlyConfigured, call_command, 'build_solr_schema', using='whoosh',
150+
interactive=False)
155151

156152
class AppModelManagementCommandTestCase(TestCase):
157153
fixtures = ['bulk_data.json']

0 commit comments

Comments
 (0)