disable ES indexing for non-ES TestCase

This commit is contained in:
Chris Van 2012-01-11 17:23:44 -08:00
Родитель 5e79b4df05
Коммит 804be6f55a
2 изменённых файлов: 36 добавлений и 1 удалений

Просмотреть файл

@ -21,8 +21,8 @@ import test_utils
import amo
from amo.urlresolvers import Prefixer, get_url_prefix, set_url_prefix
import addons.search
from addons.models import Addon, Category, Persona
import addons.search
from applications.models import Application, AppVersion
from files.models import File, Platform
from translations.models import Translation
@ -166,6 +166,14 @@ class TestCase(RedisTest, test_utils.TestCase):
def _pre_setup(self):
super(TestCase, self)._pre_setup()
self.reset_featured_addons()
# Mock out ES indexing for non-ES tests.
if not getattr(self, 'es', False):
for p in ['addons.tasks.index_addons',
'addons.tasks.unindex_addons',
'amo.models.SearchMixin']:
patcher = mock.patch(p)
patcher.start()
self.addCleanup(patcher.stop)
def reset_featured_addons(self):
from addons.cron import reset_featured_addons

Просмотреть файл

@ -6,6 +6,7 @@ from nose.tools import eq_
import amo.tests
import amo.utils
from addons.models import Addon
import addons.tasks
class TestESIndexing(amo.tests.ESTestCase):
@ -23,6 +24,32 @@ class TestESIndexing(amo.tests.ESTestCase):
Addon.objects.filter(disabled_by_user=False,
status__in=amo.VALID_STATUSES).count())
def test_real_indexing(self):
def check(s):
assert callable(s) and not isinstance(s, mock.Mock)
check(addons.tasks.index_addons)
check(addons.tasks.unindex_addons)
check(amo.models.SearchMixin)
class TestNoESIndexing(amo.tests.TestCase):
def test_no_es(self):
assert not getattr(self, 'es', False), (
'TestCase should not have "es" attribute')
def test_mocked_indexing(self):
def check(s):
assert callable(s) and isinstance(s, mock.Mock)
check(addons.tasks.index_addons)
check(addons.tasks.unindex_addons)
check(amo.models.SearchMixin)
def test_not_indexed(self):
addon = Addon.objects.create(type=amo.ADDON_EXTENSION,
status=amo.STATUS_PUBLIC)
eq_(Addon.search().filter(id__in=addon.id).count(), 0)
class TestES(amo.tests.ESTestCase):
es = True