Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1136)

Unified Diff: tools/telemetry/third_party/gsutil/third_party/boto/tests/unit/cloudsearch2/test_exceptions.py

Issue 1258583006: Add gsutil 4.13 to telemetry/third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Undo all other changes so this just add gsutil to third_party Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/third_party/gsutil/third_party/boto/tests/unit/cloudsearch2/test_exceptions.py
diff --git a/tools/telemetry/third_party/gsutil/third_party/boto/tests/unit/cloudsearch2/test_exceptions.py b/tools/telemetry/third_party/gsutil/third_party/boto/tests/unit/cloudsearch2/test_exceptions.py
new file mode 100644
index 0000000000000000000000000000000000000000..ebf1b47cf7d402fb65b55ba460307c8455454354
--- /dev/null
+++ b/tools/telemetry/third_party/gsutil/third_party/boto/tests/unit/cloudsearch2/test_exceptions.py
@@ -0,0 +1,37 @@
+from boto.compat import json
+from tests.compat import mock, unittest
+
+from tests.unit.cloudsearch2.test_search import HOSTNAME, \
+ CloudSearchSearchBaseTest
+from boto.cloudsearch2.search import SearchConnection, SearchServiceException
+
+
+def fake_loads_value_error(content, *args, **kwargs):
+ """Callable to generate a fake ValueError"""
+ raise ValueError("HAHAHA! Totally not simplejson & you gave me bad JSON.")
+
+
+def fake_loads_json_error(content, *args, **kwargs):
+ """Callable to generate a fake JSONDecodeError"""
+ raise json.JSONDecodeError('Using simplejson & you gave me bad JSON.',
+ '', 0)
+
+
+class CloudSearchJSONExceptionTest(CloudSearchSearchBaseTest):
+ response = b'{}'
+
+ def test_no_simplejson_value_error(self):
+ with mock.patch.object(json, 'loads', fake_loads_value_error):
+ search = SearchConnection(endpoint=HOSTNAME)
+
+ with self.assertRaisesRegexp(SearchServiceException, 'non-json'):
+ search.search(q='test')
+
+ @unittest.skipUnless(hasattr(json, 'JSONDecodeError'),
+ 'requires simplejson')
+ def test_simplejson_jsondecodeerror(self):
+ with mock.patch.object(json, 'loads', fake_loads_json_error):
+ search = SearchConnection(endpoint=HOSTNAME)
+
+ with self.assertRaisesRegexp(SearchServiceException, 'non-json'):
+ search.search(q='test')

Powered by Google App Engine
This is Rietveld 408576698