Skip to content

Commit e469a9f

Browse files
ternusJon Wayne Parrott
authored andcommitted
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
1 parent 6755f61 commit e469a9f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

googleapiclient/discovery.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,15 @@ def build_from_document(
322322

323323
if isinstance(service, six.string_types):
324324
service = json.loads(service)
325+
326+
if 'rootUrl' not in service and (isinstance(http, (HttpMock,
327+
HttpMockSequence))):
328+
logger.error("You are using HttpMock or HttpMockSequence without" +
329+
"having the service discovery doc in cache. Try calling " +
330+
"build() without mocking once first to populate the " +
331+
"cache.")
332+
raise InvalidJsonError()
333+
325334
base = urljoin(service['rootUrl'], service['servicePath'])
326335
schema = Schemas(service)
327336

0 commit comments

Comments
 (0)