Add a warning when using mocking without cache (#261)
If HttpMock or HttpMockSequence is used in a test without the cache
being filled first, a strange KeyError will be thrown. This happens
on e.g. Travis CI. Unfortunately this behavior is used in the tests;
this patch adds a warning for those unfortunate enough to encounter
it.
See also: #208
diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py
index 8609e3a..598b222 100644
--- a/googleapiclient/discovery.py
+++ b/googleapiclient/discovery.py
@@ -322,6 +322,15 @@
if isinstance(service, six.string_types):
service = json.loads(service)
+
+ if 'rootUrl' not in service and (isinstance(http, (HttpMock,
+ HttpMockSequence))):
+ logger.error("You are using HttpMock or HttpMockSequence without" +
+ "having the service discovery doc in cache. Try calling " +
+ "build() without mocking once first to populate the " +
+ "cache.")
+ raise InvalidJsonError()
+
base = urljoin(service['rootUrl'], service['servicePath'])
schema = Schemas(service)