def test_get_item(self): ch = loading.ConnectionHandler({}) try: empty_engine = ch['default'] self.fail() except ImproperlyConfigured: pass ch = loading.ConnectionHandler({ 'default': { 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', 'URL': 'http://localhost:9001/solr/test_default', }, }) solr_engine = ch['default'] backend_path, memory_address = repr(solr_engine).strip('<>').split( ' object at ') self.assertEqual(backend_path, 'haystack.backends.solr_backend.SolrEngine') solr_engine_2 = ch['default'] backend_path_2, memory_address_2 = repr(solr_engine_2).strip( '<>').split(' object at ') self.assertEqual(backend_path_2, 'haystack.backends.solr_backend.SolrEngine') # Ensure we're loading out of the memorized connection. self.assertEqual(memory_address_2, memory_address) try: empty_engine = ch['slave'] self.fail() except ImproperlyConfigured: pass
def test_get_item(self): ch = loading.ConnectionHandler({}) try: empty_engine = ch["default"] self.fail() except ImproperlyConfigured: pass ch = loading.ConnectionHandler({ "default": { "ENGINE": "haystack.backends.solr_backend.SolrEngine", "URL": "http://localhost:9001/solr/test_default", } }) solr_engine = ch["default"] backend_path, memory_address = ( repr(solr_engine).strip("<>").split(" object at ")) self.assertEqual(backend_path, "haystack.backends.solr_backend.SolrEngine") solr_engine_2 = ch["default"] backend_path_2, memory_address_2 = ( repr(solr_engine_2).strip("<>").split(" object at ")) self.assertEqual(backend_path_2, "haystack.backends.solr_backend.SolrEngine") # Ensure we're loading out of the memorized connection. self.assertEqual(memory_address_2, memory_address) try: empty_engine = ch["slave"] self.fail() except ImproperlyConfigured: pass
def test_init(self): ch = loading.ConnectionHandler({}) self.assertEqual(ch.connections_info, {}) ch = loading.ConnectionHandler({ 'default': { 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', 'URL': 'http://localhost:9001/solr/test_default', }, }) self.assertEqual(ch.connections_info, { 'default': { 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', 'URL': 'http://localhost:9001/solr/test_default', }, })
def test_init(self): ch = loading.ConnectionHandler({}) self.assertEqual(ch.connections_info, {}) ch = loading.ConnectionHandler({ "default": { "ENGINE": "haystack.backends.solr_backend.SolrEngine", "URL": "http://localhost:9001/solr/test_default", } }) self.assertEqual( ch.connections_info, { "default": { "ENGINE": "haystack.backends.solr_backend.SolrEngine", "URL": "http://localhost:9001/solr/test_default", } }, )
def test_get_unified_index(self): ch = loading.ConnectionHandler( {"default": {"ENGINE": "haystack.backends.simple_backend.SimpleEngine"}} ) ui = ch["default"].get_unified_index() klass, address = repr(ui).strip("<>").split(" object at ") self.assertEqual(str(klass), "haystack.utils.loading.UnifiedIndex") ui_2 = ch["default"].get_unified_index() klass_2, address_2 = repr(ui_2).strip("<>").split(" object at ") self.assertEqual(str(klass_2), "haystack.utils.loading.UnifiedIndex") self.assertEqual(address_2, address)
def test_get_unified_index(self): ch = loading.ConnectionHandler({ 'default': { 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', } }) ui = ch['default'].get_unified_index() klass, address = repr(ui).strip('<>').split(' object at ') self.assertEqual(str(klass), 'haystack.utils.loading.UnifiedIndex') ui_2 = ch['default'].get_unified_index() klass_2, address_2 = repr(ui_2).strip('<>').split(' object at ') self.assertEqual(str(klass_2), 'haystack.utils.loading.UnifiedIndex') self.assertEqual(address_2, address)
) if hasattr(settings, 'HAYSTACK_INCLUDE_SPELLING'): raise ImproperlyConfigured( 'The HAYSTACK_INCLUDE_SPELLING setting is now a per-backend setting & belongs in HAYSTACK_CONNECTIONS.' ) # Check the 2.X+ bits. if not hasattr(settings, 'HAYSTACK_CONNECTIONS'): raise ImproperlyConfigured('The HAYSTACK_CONNECTIONS setting is required.') if DEFAULT_ALIAS not in settings.HAYSTACK_CONNECTIONS: raise ImproperlyConfigured( "The default alias '%s' must be included in the HAYSTACK_CONNECTIONS setting." % DEFAULT_ALIAS) # Load the connections. connections = loading.ConnectionHandler(settings.HAYSTACK_CONNECTIONS) # Load the router(s). connection_router = loading.ConnectionRouter() if hasattr(settings, 'HAYSTACK_ROUTERS'): if not isinstance(settings.HAYSTACK_ROUTERS, (list, tuple)): raise ImproperlyConfigured( "The HAYSTACK_ROUTERS setting must be either a list or tuple.") connection_router = loading.ConnectionRouter(settings.HAYSTACK_ROUTERS) # Setup the signal processor. signal_processor_path = getattr(settings, 'HAYSTACK_SIGNAL_PROCESSOR', 'haystack.signals.BaseSignalProcessor') signal_processor_class = loading.import_class(signal_processor_path)
def patch_connections(self): haystack.connections = loading.ConnectionHandler({ haystack.DEFAULT_ALIAS: { 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', }, })