Permalink
Browse files

Applying some notes from the PR

  • Loading branch information...
Evan Fagerberg authored and efagerberg committed Jul 19, 2017
1 parent 966aaba commit f280776b2fcfe2552fe0b06b5539e56783f43f18
Showing with 37 additions and 32 deletions.
  1. +1 −3 .gitignore
  2. +3 −9 pysolr.py
  3. +33 −20 tests/test_client.py
View
@@ -1,6 +1,4 @@
.tox
solr*.tgz
solr-app
solr
*.pyc
logs
solr
View
@@ -442,11 +442,6 @@ def _mlt(self, params, handler='mlt'):
def _suggest_terms(self, params, handler='terms'):
return self._select(params, handler)
def _get_commit(self, commit):
if commit is None:
commit = self.commit_by_default
return commit
def _update(self, message, clean_ctrl_chars=True, commit=None, softCommit=False, waitFlush=None, waitSearcher=None,
overwrite=None, handler='update'):
"""
@@ -471,7 +466,9 @@ def _update(self, message, clean_ctrl_chars=True, commit=None, softCommit=False,
path = '%s/' % path_handler
commit = self._get_commit(commit)
if commit is None:
commit = self.commit_by_default
if commit:
query_vars.append('commit=%s' % str(bool(commit)).lower())
elif softCommit:
@@ -909,7 +906,6 @@ def add(self, docs, boost=None, fieldUpdates=None, commit=None, softCommit=False
m = force_unicode(m)
end_time = time.time()
commit = self._get_commit(commit)
self.log.debug("Built add request of %s docs in %0.2f seconds.", len(message), end_time - start_time)
return self._update(m, commit=commit, softCommit=softCommit, waitFlush=waitFlush, waitSearcher=waitSearcher,
overwrite=overwrite, handler=handler)
@@ -954,8 +950,6 @@ def delete(self, id=None, q=None, commit=None, softCommit=False, waitFlush=None,
elif q is not None:
m = '<delete><query>%s</query></delete>' % q
commit = self._get_commit(commit)
return self._update(m, commit=commit, softCommit=softCommit, waitFlush=waitFlush, waitSearcher=waitSearcher, handler=handler)
def commit(self, softCommit=False, waitFlush=None, waitSearcher=None, expungeDeletes=None, handler='update'):
View
@@ -441,13 +441,6 @@ def test__to_python(self):
self.assertEqual(self.solr._to_python(('foo', 'bar')), 'foo')
self.assertEqual(self.solr._to_python('tuple("foo", "bar")'), 'tuple("foo", "bar")')
def test__get_commit(self):
# Should return false unless given True
self.assertTrue(self.solr._get_commit(True))
self.assertFalse(self.solr._get_commit(False))
self.assertFalse(self.solr._get_commit(None))
def test__is_null_value(self):
self.assertTrue(self.solr._is_null_value(None))
self.assertTrue(self.solr._is_null_value(''))
@@ -786,6 +779,21 @@ def test_commit(self):
self.assertTrue(args[1].startswith('update/?'))
self.assertEqual(len(self.solr.search('doc')), 4)
def test_can_handles_default_commit_policy(self):
expected_commits = [False, True, False]
commit_arg = [False, True, None]
for expected_commit, arg in zip(expected_commits, commit_arg):
self.solr.add([
{
'id': 'doc_6',
'title': 'Newly added doc',
}
], commit=arg)
args, _ = self.solr._send_request.call_args
committing_in_url = 'commit' in args[1]
self.assertEqual(expected_commit, committing_in_url)
def test_overwrite(self):
self.assertEqual(len(self.solr.search('id:doc_overwrite_1')), 0)
self.solr.add([
@@ -916,15 +924,7 @@ class SolrCommitByDefaultTestCase(unittest.TestCase, SolrTestCaseMixin):
def setUp(self):
super(SolrCommitByDefaultTestCase, self).setUp()
self.solr = self.get_solr("core0", commit_by_default=True)
def test__get_commit(self):
# Should return True unless given False
self.assertTrue(self.solr._get_commit(True))
self.assertFalse(self.solr._get_commit(False))
self.assertTrue(self.solr._get_commit(None))
def test_does_not_require_commit(self):
docs = [
self.docs = [
{
'id': 'doc_1',
'title': 'Newly added doc',
@@ -934,19 +934,32 @@ def test_does_not_require_commit(self):
'title': 'Another example doc',
},
]
def test_does_not_require_commit(self):
# add should not require commit arg
self.solr.add(docs)
self.solr.add(self.docs)
self.assertEqual(len(self.solr.search('doc')), 2)
self.assertEqual(len(self.solr.search('example')), 1)
# update should not require commit arg
docs[0]['title'] = "Updated Doc"
docs[1]['title'] = "Another example updated doc"
self.solr.add(docs, fieldUpdates={'title': 'set'})
self.docs[0]['title'] = "Updated Doc"
self.docs[1]['title'] = "Another example updated doc"
self.solr.add(self.docs, fieldUpdates={'title': 'set'})
self.assertEqual(len(self.solr.search('updated')), 2)
self.assertEqual(len(self.solr.search('example')), 1)
# delete should not require commit arg
self.solr.delete(q='*:*')
self.assertEqual(len(self.solr.search('*')), 0)
def test_can_handles_default_commit_policy(self):
self.solr._send_request = Mock(wraps=self.solr._send_request)
expected_commits = [False, True, True]
commit_arg = [False, True, None]
for expected_commit, arg in zip(expected_commits, commit_arg):
self.solr.add(self.docs, commit=arg)
args, _ = self.solr._send_request.call_args
committing_in_url = 'commit' in args[1]
self.assertEqual(expected_commit, committing_in_url)

0 comments on commit f280776

Please sign in to comment.