Skip to content

Commit

Permalink
#1 - Started trimming es dsl.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentguilbert committed Dec 29, 2016
1 parent e264ce5 commit 120e506
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 453 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ node_modules/
nose_trampoline.egg-info/
parts/
trampoline.log
ve/
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

install_requires = [
'celery',
'elasticsearch_dsl>=2.0.0,<3.0.0',
'tqdm',
'elasticsearch',
'six',
'tqdm',
]
if sys.version_info.major == 2:
install_requires.append('futures')
Expand Down
36 changes: 18 additions & 18 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@
class BaseTestCase(TransactionTestCase):

def refresh(self):
trampoline_config.connection.indices.refresh('_all')
trampoline_config.es.indices.refresh('_all')

def docExists(self, obj, obj_id):
def docExists(self, obj):
doc_type = obj.get_es_doc_type()
doc_type_name = doc_type._doc_type.name
index_name = doc_type._doc_type.index
obj_id = obj_id or obj.pk
return trampoline_config.connection.exists(
index=index_name,
doc_type=doc_type_name,
id=obj_id,
index = obj.get_es_index()
return trampoline_config.es.exists(
index=index,
doc_type=doc_type,
id=obj.pk
)

def aliasExists(self, index, name):
return trampoline_config.connection.indices.exists_alias(
return trampoline_config.es.indices.exists_alias(
index=index, name=name)

def indexExists(self, index):
return trampoline_config.connection.indices.exists(index=index)
return trampoline_config.es.indices.exists(index=index)

def typeExists(self, index, doc_type_name):
return trampoline_config.connection.indices.exists_type(
index=index, doc_type=doc_type_name)
def typeExists(self, index, doc_type):
return trampoline_config.es.indices.exists_type(
index=index,
doc_type=doc_type
)

def assertAliasExists(self, index, name):
self.assertTrue(self.aliasExists(index, name))
Expand All @@ -53,8 +53,8 @@ def assertTypeExists(self, index, doc_type):
def assertTypeDoesntExist(self, index, doc_type):
self.assertFalse(self.typeExists(index, doc_type))

def assertDocExists(self, obj, obj_id=None):
self.assertTrue(self.docExists(obj, obj_id))
def assertDocExists(self, obj):
self.assertTrue(self.docExists(obj))

def assertDocDoesntExist(self, obj, obj_id=None):
self.assertFalse(self.docExists(obj, obj_id))
def assertDocDoesntExist(self, obj):
self.assertFalse(self.docExists(obj))
27 changes: 0 additions & 27 deletions tests/doc_types.py

This file was deleted.

49 changes: 25 additions & 24 deletions tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,42 @@
"""
from django.db import models

from tests.doc_types import TokenDoc, PersonDoc
from trampoline.mixins import ESIndexableMixin


class TokenSerializer(object):

def __init__(self, token, *args, **kwargs):
self.token = token

@property
def data(self):
return {
'name': self.token.name,
'number': self.token.number,
}


class Token(ESIndexableMixin, models.Model):
name = models.CharField(max_length=200)
name = models.CharField(default='token', max_length=200)
number = models.IntegerField(default=42)

es_serializer = TokenSerializer

def __unicode__(self):
return self.name

es_doc_type = TokenDoc

def is_indexable(self):
if self.name == 'not_indexable':
return False
return True

@classmethod
def get_indexable_queryset(cls):
return Token.objects.all()

def get_es_doc_mapping(self):
doc = TokenDoc()
doc.name = self.name
if doc.name == 'raise_exception':
raise RuntimeError
return doc


class Person(ESIndexableMixin, models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)

def __unicode__(self):
return self.name

es_doc_type = PersonDoc
es_auto_doc_type_mapping = True
def get_es_doc_type_mapping(self):
return {
'properties': {
'name': {
'type': 'string'
}
}
}
16 changes: 6 additions & 10 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Test settings for trampoline.
"""

DEBUG = True

DATABASES = {
'default': {
'NAME': 'trampoline.db',
Expand Down Expand Up @@ -41,20 +43,14 @@
##################################################

TRAMPOLINE = {
'INDICES': {
'foobar': {
'models': [
'tests.models.Token',
# Make sure only one doc_type is created.
'tests.models.Token',
'tests.models.Person',
]
},
},
'MODELS': [
'tests.models.Token',
],
'OPTIONS': {
'disabled': False,
'fail_silently': True,
},
'VERSION_SUFFIX': '_1',
}

##################################################
Expand Down
Loading

0 comments on commit 120e506

Please sign in to comment.