| OLD | NEW |
| (Empty) | |
| 1 import mock |
| 2 from boto.compat import json |
| 3 from tests.unit import unittest |
| 4 |
| 5 from .test_search import HOSTNAME, CloudSearchSearchBaseTest |
| 6 from boto.cloudsearch2.search import SearchConnection, SearchServiceException |
| 7 |
| 8 |
| 9 def fake_loads_value_error(content, *args, **kwargs): |
| 10 """Callable to generate a fake ValueError""" |
| 11 raise ValueError("HAHAHA! Totally not simplejson & you gave me bad JSON.") |
| 12 |
| 13 |
| 14 def fake_loads_json_error(content, *args, **kwargs): |
| 15 """Callable to generate a fake JSONDecodeError""" |
| 16 raise json.JSONDecodeError('Using simplejson & you gave me bad JSON.', |
| 17 '', 0) |
| 18 |
| 19 |
| 20 class CloudSearchJSONExceptionTest(CloudSearchSearchBaseTest): |
| 21 response = '{}' |
| 22 |
| 23 def test_no_simplejson_value_error(self): |
| 24 with mock.patch.object(json, 'loads', fake_loads_value_error): |
| 25 search = SearchConnection(endpoint=HOSTNAME) |
| 26 |
| 27 with self.assertRaisesRegexp(SearchServiceException, 'non-json'): |
| 28 search.search(q='test') |
| 29 |
| 30 @unittest.skipUnless(hasattr(json, 'JSONDecodeError'), |
| 31 'requires simplejson') |
| 32 def test_simplejson_jsondecodeerror(self): |
| 33 with mock.patch.object(json, 'loads', fake_loads_json_error): |
| 34 search = SearchConnection(endpoint=HOSTNAME) |
| 35 |
| 36 with self.assertRaisesRegexp(SearchServiceException, 'non-json'): |
| 37 search.search(q='test') |
| OLD | NEW |