From 90b121cc9729a541c7b7c00147884fdb8d858a04 Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Tue, 15 Jan 2013 17:25:12 +0100 Subject: [PATCH 1/4] .gitignore maintenance --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b6b8dd6..df5a05a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,11 @@ -*.pyc +*.py[co] *.egg-info .tox build/ docs/_build/ dist/ .DS_Store +/bin +/include +/lib +.Python From 1a9c4fe4c082a4c2069df1b91de6eab43f38bb66 Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Tue, 15 Jan 2013 17:25:41 +0100 Subject: [PATCH 2/4] added some tests for _get_add_xml --- tests/test_utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/test_utils.py diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..f0fd8b0 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,23 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import unittest +from mysolr import mysolr + + +class AddXmlTestCase(unittest.TestCase): + + def test_add_xml(self): + self.assertEqual(mysolr._get_add_xml([{'id':5, 'foo':'bar'}]), + ('bar' + '5')) + + def test_add_xml_nooverwrite(self): + self.assertEqual(mysolr._get_add_xml([{'id':5, 'foo':'bar'}], + overwrite=False), + ('bar' + '5')) + + +if __name__ == '__main__': + unittest.main() From 9b412bb96c987614fffc1f73888fa79b2239bc7f Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Tue, 15 Jan 2013 17:43:22 +0100 Subject: [PATCH 3/4] add commitWithin and boost options restructure to meet DRY principle --- mysolr/mysolr.py | 34 +++++++++++++++++++++++++--------- tests/test_utils.py | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/mysolr/mysolr.py b/mysolr/mysolr.py index bfad496..d9b50b2 100644 --- a/mysolr/mysolr.py +++ b/mysolr/mysolr.py @@ -351,7 +351,8 @@ def fetch(self, rows=None): self.query['start'] += self.query['rows'] -def _get_add_xml(array_of_hash, overwrite=True): +def _get_add_xml(array_of_hash, overwrite=True, commit_within=None, + boost_values=None): """ Creates add XML message to send to Solr based on the array of hashes (documents) provided. @@ -359,19 +360,34 @@ def _get_add_xml(array_of_hash, overwrite=True): with the same uniqueKey (default is True) """ - xml = '' % ('true' if overwrite else 'false') + xml = 'bar' '5')) + def test_add_xml_commit_within(self): + self.assertEqual(mysolr._get_add_xml([{'id':5, 'foo':'bar'}], + commit_within=2.0), + ('' + 'bar5' + '')) + + def test_add_xml_commit_doc_boost(self): + self.assertEqual(mysolr._get_add_xml([{'id':7, 'foo':'bar'}], + boost_values={'':2.3}), + ('' + 'bar7' + '')) + + def test_add_xml_commit_field_boost(self): + self.assertEqual(mysolr._get_add_xml([{'id':7, 'foo':'bar'}], + boost_values={'foo':4.2}), + ('' + 'bar' + '7')) if __name__ == '__main__': unittest.main() From 63f8c92336973ac522edbaa692c78757118e5c21 Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Tue, 15 Jan 2013 17:49:30 +0100 Subject: [PATCH 4/4] pep8 --- tests/test_utils.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 7a4a2e4..3ec7198 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- import unittest from mysolr import mysolr @@ -8,33 +8,33 @@ class AddXmlTestCase(unittest.TestCase): def test_add_xml(self): - self.assertEqual(mysolr._get_add_xml([{'id':5, 'foo':'bar'}]), + self.assertEqual(mysolr._get_add_xml([{'id': 5, 'foo': 'bar'}]), ('bar' '5')) def test_add_xml_nooverwrite(self): - self.assertEqual(mysolr._get_add_xml([{'id':5, 'foo':'bar'}], + self.assertEqual(mysolr._get_add_xml([{'id': 5, 'foo': 'bar'}], overwrite=False), ('bar' '5')) def test_add_xml_commit_within(self): - self.assertEqual(mysolr._get_add_xml([{'id':5, 'foo':'bar'}], + self.assertEqual(mysolr._get_add_xml([{'id': 5, 'foo': 'bar'}], commit_within=2.0), ('' 'bar5' '')) def test_add_xml_commit_doc_boost(self): - self.assertEqual(mysolr._get_add_xml([{'id':7, 'foo':'bar'}], - boost_values={'':2.3}), + self.assertEqual(mysolr._get_add_xml([{'id': 7, 'foo': 'bar'}], + boost_values={'': 2.3}), ('' 'bar7' '')) def test_add_xml_commit_field_boost(self): - self.assertEqual(mysolr._get_add_xml([{'id':7, 'foo':'bar'}], - boost_values={'foo':4.2}), + self.assertEqual(mysolr._get_add_xml([{'id': 7, 'foo': 'bar'}], + boost_values={'foo': 4.2}), ('' 'bar' '7'))