Commit 2589ab73 authored by ale's avatar ale

remove obsolete test for component that no longer exists

parent bf652888
import mox
import solr
import unittest
from datetime import datetime
from lens2 import api
class null_parser(object):
"""A 'null' parser, capable of inserting errors in the datastream."""
def parse(self, s):
if s == 'value error':
raise ValueError('oh no!')
return s
class results_stub(object):
def __init__(self, docs, num_results=None):
self.results = docs
self.numFound = num_results or len(docs)
class LensClientTest(unittest.TestCase):
def setUp(self):
self.mox = mox.Mox()
def tearDown(self):
self.mox.VerifyAll()
self.mox.UnsetStubs()
def _create_solr(self):
solr_stub = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(solr, 'Solr', use_mock_anything=True)
solr.Solr('http://localhost/solr', persistent=True,
timeout=api.SOLR_TIMEOUT, max_retries=api.SOLR_RETRIES,
http_user=None, http_pass=None).AndReturn(solr_stub)
return solr_stub
def test_insert(self):
docs = [{'msg': 'one'},
{'msg': 'two'},
{'msg': 'three'}]
solr_stub = self._create_solr()
solr_stub.add_many(docs, commit=False)
solr_stub.commit(wait_flush=False, wait_searcher=False)
self.mox.ReplayAll()
client = api.LensClient('http://localhost/solr')
client.insert(docs, null_parser())
def test_insert_with_parse_errors(self):
docs = [{'msg': 'one'},
'value error',
{'msg': 'three'}]
real_docs = filter(lambda x: isinstance(x, dict), docs)
solr_stub = self._create_solr()
solr_stub.add_many(real_docs, commit=False)
solr_stub.commit(wait_flush=False, wait_searcher=False)
self.mox.ReplayAll()
client = api.LensClient('http://localhost/solr')
client.insert(docs, null_parser())
def test_insert_batching(self):
docs = [{'msg': 'msg%d' % x} for x in xrange(100)]
solr_stub = self._create_solr()
for i in range(5):
solr_stub.add_many(docs[i*20:(i+1)*20], commit=False)
solr_stub.commit(wait_flush=False, wait_searcher=False)
self.mox.ReplayAll()
client = api.LensClient('http://localhost/solr')
client.insert(docs, null_parser(), batch_size=20)
def test_search_simple(self):
docs = [{'msg': 'msg1'}, {'msg': 'msg2'}]
solr_stub = self._create_solr()
solr_stub.select(q='query', sort='timestamp asc', fields='*',
start=0, rows=api.SEARCH_BATCH_SIZE).AndReturn(
results_stub(docs))
self.mox.ReplayAll()
client = api.LensClient('http://localhost/solr')
results = list(client.search('query'))
self.assertEquals(docs, results)
def test_search_simple_paginated(self):
docs = [{'msg': 'msg1'}, {'msg': 'msg2'}]
solr_stub = self._create_solr()
solr_stub.select(q='query', sort='timestamp asc', fields='*',
start=10, rows=3).AndReturn(
results_stub(docs, 4000))
self.mox.ReplayAll()
client = api.LensClient('http://localhost/solr')
results = list(client.search('query', offset=10, limit=3))
self.assertEquals(docs, results)
def test_search_batch(self):
n_docs = 2 * api.SEARCH_BATCH_SIZE
docs = [{'msg': 'msg%d' % x} for x in xrange(n_docs)]
solr_stub = self._create_solr()
solr_stub.select(q='query', sort='timestamp asc', fields='*',
start=0, rows=api.SEARCH_BATCH_SIZE).AndReturn(
results_stub(docs[:api.SEARCH_BATCH_SIZE], n_docs))
solr_stub.select(q='query', sort='timestamp asc', fields='*',
start=api.SEARCH_BATCH_SIZE,
rows=api.SEARCH_BATCH_SIZE).AndReturn(
results_stub(docs[api.SEARCH_BATCH_SIZE:], n_docs))
self.mox.ReplayAll()
client = api.LensClient('http://localhost/solr')
results = list(client.search('query'))
self.assertEquals(docs, results)
def test_search_time_range(self):
docs = [{'msg': 'msg1'}, {'msg': 'msg2'}]
solr_stub = self._create_solr()
trange = (datetime(2010, 12, 13, 0, 0, 0), None)
solr_stub.select(q='(query) AND (timestamp:[2010-12-13T00:00:00Z TO NOW])',
sort='timestamp asc', fields='*',
start=0, rows=api.SEARCH_BATCH_SIZE).AndReturn(
results_stub(docs))
self.mox.ReplayAll()
client = api.LensClient('http://localhost/solr')
results = list(client.search('query', time_range=trange))
self.assertEquals(docs, results)
def test_expire(self):
limit = datetime(2010, 12, 13, 0, 0, 0)
solr_stub = self._create_solr()
solr_stub.delete_query('timestamp:[* TO 2010-12-13T00:00:00Z]')
solr_stub.commit()
self.mox.ReplayAll()
client = api.LensClient('http://localhost/solr')
client.expire(limit)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment