Skip to content

Commit

Permalink
Passing test from django 1.4 to 1.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
lauxley committed Jan 21, 2015
1 parent cafa478 commit f73dc09
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
13 changes: 13 additions & 0 deletions django_elasticsearch/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
]
Empty file.
4 changes: 1 addition & 3 deletions django_elasticsearch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from django_elasticsearch.serializers import ModelJsonSerializer
from django_elasticsearch.managers import ElasticsearchManager

ELASTICSEARCH_AUTO_INDEX = getattr(settings, 'ELASTICSEARCH_AUTO_INDEX', True)


class EsIndexable(Model):
"""
Expand Down Expand Up @@ -75,7 +73,7 @@ def es_syncdb_callback(sender, app, created_models, **kwargs):
model.es.create_index()


if ELASTICSEARCH_AUTO_INDEX and not settings.DEBUG:
if getattr(settings, 'ELASTICSEARCH_AUTO_INDEX', False) and not getattr(settings, 'DEBUG', False):
# Note: can't specify the sender class because EsIndexable is Abstract,
# see: https://code.djangoproject.com/ticket/9318
post_save.connect(es_save_callback)
Expand Down
2 changes: 2 additions & 0 deletions django_elasticsearch/tests/test_indexable.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def test_get_mapping(self):
'date_joined': {u'type': u'date', u'format': u'dateOptionalTime'}
}

# reset the eventual cache on the Model mapping
TestModel.es._mapping = None
mapping = TestModel.es.get_mapping()
self.assertEqual(expected, mapping)

Expand Down
21 changes: 11 additions & 10 deletions django_elasticsearch/tests/test_qs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mock

import django
from django.test import TestCase
from django.test.utils import override_settings

Expand All @@ -13,26 +14,27 @@
ELASTICSEARCH_AUTO_INDEX=False,
ELASTICSEARCH_SETTINGS={})
class EsQuerysetTestCase(TestCase):

def setUp(self):
# create a bunch of documents
TestModel.es.create_index(ignore=True)

self.t1 = TestModel.objects.create(username=u"woot woot", first_name=u"John", last_name=u"Smith")
self.t1.es.do_index()

self.t2 = TestModel.objects.create(username=u"woot", first_name=u"Jack", last_name=u"Smith")
self.t2.es.do_index()

self.t3 = TestModel.objects.create(username=u"BigMama", first_name=u"Mama", last_name=u"Smith")
self.t3.es.do_index()

self.t4 = TestModel.objects.create(username=u"foo", first_name=u"Foo", last_name=u"Bar")
self.t4.es.do_index()

# django 1.7 seems to handle settings differently than previous version
# which make the override of ELASTICSEARCH_AUTO_INDEX actually work
if django.VERSION[1] <= 7:
self.t1.es.do_index()
self.t2.es.do_index()
self.t3.es.do_index()
self.t4.es.do_index()

TestModel.es.do_update()

def tearDown(self):
super(EsQuerysetTestCase, self).tearDown()
es_client.indices.delete(index=TestModel.es.get_index())

def test_all(self):
Expand Down Expand Up @@ -94,8 +96,7 @@ def test_suggestions(self):
u'last_name': [
{u'length': 5,
u'offset': 0,
# TODO: understand why the `freq` attribute is 6 when there is only 3 hits ?
u'options': [{u'freq': 6,
u'options': [{u'freq': 3,
u'score': 0.8,
u'text': u'smith'}],
u'text': u'smath'}]}
Expand Down
5 changes: 4 additions & 1 deletion test_project/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
django>=1.6.8
#
django>=1.7, <1.8
# django>=1.4, <1.5
# django>=1.6, <1.7

# dev tools
mock
Expand Down
2 changes: 2 additions & 0 deletions test_project/test_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

REST_FRAMEWORK = {}

TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.4/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
Expand Down

0 comments on commit f73dc09

Please sign in to comment.