<s> from __future__ import absolute_import <EOL> import os <EOL> import logging <EOL> import unittest <EOL> from pprint import pprint <EOL> from pyes . es import ES <EOL> from pyes . helpers import SettingsBuilder <EOL> """<STR_LIT>""" <EOL> def get_conn ( * args , ** kwargs ) : <EOL> return ES ( ( "<STR_LIT:http>" , "<STR_LIT:127.0.0.1>" , <NUM_LIT> ) , * args , ** kwargs ) <EOL> class ESTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . log = open ( "<STR_LIT>" % self . _testMethodName , "<STR_LIT:wb>" ) <EOL> self . conn = get_conn ( timeout = <NUM_LIT> , log_curl = True , dump_curl = self . log ) <EOL> self . index_name = "<STR_LIT>" <EOL> self . document_type = "<STR_LIT>" <EOL> self . conn . indices . delete_index_if_exists ( self . index_name ) <EOL> def tearDown ( self ) : <EOL> self . conn . indices . delete_index_if_exists ( self . index_name ) <EOL> if self . log : <EOL> self . log . close ( ) <EOL> def assertResultContains ( self , result , expected ) : <EOL> for ( key , value ) in expected . items ( ) : <EOL> found = False <EOL> try : <EOL> found = value == result [ key ] <EOL> except KeyError : <EOL> if result . has_key ( '<STR_LIT>' ) : <EOL> found = value == result [ '<STR_LIT>' ] [ key ] <EOL> self . assertEqual ( True , found ) <EOL> def checkRaises ( self , excClass , callableObj , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> callableObj ( * args , ** kwargs ) <EOL> except excClass as e : <EOL> return e <EOL> else : <EOL> raise self . failureException ( "<STR_LIT>" % excClass ) <EOL> def get_datafile ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> return open ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT:data>" , filename ) , "<STR_LIT:rb>" ) . read ( ) <EOL> def get_datafile_path ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> return os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT:data>" , filename ) <EOL> def dump ( self , result ) : <EOL> """<STR_LIT>""" <EOL> pprint ( result ) <EOL> def init_default_index ( self ) : <EOL> settings = SettingsBuilder ( { '<STR_LIT>' : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:1> } ) <EOL> from pyes . mappings import DocumentObjectField <EOL> from pyes . mappings import IntegerField <EOL> from pyes . mappings import NestedObject <EOL> from pyes . mappings import StringField , DateField <EOL> docmapping = DocumentObjectField ( name = self . document_type ) <EOL> docmapping . add_property ( <EOL> StringField ( name = "<STR_LIT>" , store = True , term_vector = "<STR_LIT>" , index = "<STR_LIT>" ) ) <EOL> docmapping . add_property ( <EOL> StringField ( name = "<STR_LIT:name>" , store = True , term_vector = "<STR_LIT>" , index = "<STR_LIT>" ) ) <EOL> docmapping . add_property ( <EOL> StringField ( name = "<STR_LIT:title>" , store = True , term_vector = "<STR_LIT>" , index = "<STR_LIT>" ) ) <EOL> docmapping . add_property ( IntegerField ( name = "<STR_LIT>" , store = True ) ) <EOL> docmapping . add_property ( DateField ( name = "<STR_LIT:date>" , store = True ) ) <EOL> docmapping . add_property ( StringField ( name = "<STR_LIT>" , store = True , index = "<STR_LIT>" ) ) <EOL> nested_object = NestedObject ( name = "<STR_LIT>" ) <EOL> nested_object . add_property ( StringField ( name = "<STR_LIT:name>" , store = True ) ) <EOL> nested_object . add_property ( StringField ( name = "<STR_LIT:value>" , store = True ) ) <EOL> nested_object . add_property ( IntegerField ( name = "<STR_LIT>" , store = True ) ) <EOL> docmapping . add_property ( nested_object ) <EOL> settings . add_mapping ( docmapping ) <EOL> self . conn . ensure_index ( self . index_name , settings ) <EOL> def setUp ( ) : <EOL> """<STR_LIT>""" <EOL> mapping = { <EOL> u'<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT:1.0> , <EOL> '<STR_LIT:index>' : '<STR_LIT>' , <EOL> '<STR_LIT:store>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT:type>' : u'<STR_LIT:string>' , <EOL> "<STR_LIT>" : "<STR_LIT>" } , <EOL> u'<STR_LIT:name>' : { <EOL> '<STR_LIT>' : <NUM_LIT:1.0> , <EOL> '<STR_LIT:index>' : '<STR_LIT>' , <EOL> '<STR_LIT:store>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT:type>' : u'<STR_LIT:string>' , <EOL> "<STR_LIT>" : "<STR_LIT>" } , <EOL> u'<STR_LIT:title>' : { <EOL> '<STR_LIT>' : <NUM_LIT:1.0> , <EOL> '<STR_LIT:index>' : '<STR_LIT>' , <EOL> '<STR_LIT:store>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT:type>' : u'<STR_LIT:string>' , <EOL> "<STR_LIT>" : "<STR_LIT>" } , <EOL> u'<STR_LIT>' : { <EOL> '<STR_LIT:store>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT:type>' : u'<STR_LIT>' } , <EOL> u'<STR_LIT>' : { <EOL> '<STR_LIT:store>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT:type>' : u'<STR_LIT>' } , <EOL> u'<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT:1.0> , <EOL> '<STR_LIT:index>' : '<STR_LIT>' , <EOL> '<STR_LIT:store>' : '<STR_LIT:yes>' , <EOL> '<STR_LIT:type>' : u'<STR_LIT:string>' } } <EOL> conn = get_conn ( log_curl = True ) <EOL> conn . indices . delete_index_if_exists ( "<STR_LIT>" ) <EOL> conn . indices . create_index ( "<STR_LIT>" ) <EOL> conn . indices . put_mapping ( "<STR_LIT>" , { '<STR_LIT>' : mapping } , [ "<STR_LIT>" ] ) <EOL> conn . index ( { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : [ <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> ] } , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> ) <EOL> conn . index ( { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : [ <NUM_LIT:0.1> , <NUM_LIT> , <NUM_LIT> ] } , "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:2> ) <EOL> conn . indices . refresh ( [ "<STR_LIT>" ] ) <EOL> def tearDown ( ) : <EOL> """<STR_LIT>""" <EOL> conn = get_conn ( ) <EOL> conn . indices . delete_index_if_exists ( "<STR_LIT>" ) </s>
