google-api-python-client icon indicating copy to clipboard operation
google-api-python-client copied to clipboard

Unable to use HttpMock

Open gmyrianthous opened this issue 3 years ago • 1 comments

Environment details

  • OS type and version: macOS Monterey (v12.5.1)
  • Python version: Python 3.8.13
  • pip version: pip 22.0.4
  • google-api-python-client version: google-api-python-client==1.12.11

Steps to reproduce

  1. ?
  2. ?

Code example

def test_service():
    http = HttpMock('tests/include/gmail/resources/mock-email-ids.json', {'status': '200'})
    service = build('gmail', 'v1', http=http)
    response = service.users().messages().list(userId='me').execute()

where tests/include/gmail/resources/mock-email-ids.json is:

{
   "messages":[
      {
         "id":"12345",
         "threadId":"12345"
      },
      {
         "id":"6789",
         "threadId":"6789"
      }
   ],
   "resultSizeEstimate":2
}

Stack trace

ERROR    googleapiclient.discovery:discovery.py:485 You are using HttpMock or HttpMockSequence withouthaving the service discovery doc in cache. Try calling build() without mocking once first to populate the cache.

I've even tried to run it without http argument (which in non-sense, what am I going to do if this is part of a CI/CD pipeline?), but still the same issue afterwards.

gmyrianthous avatar Nov 14 '22 12:11 gmyrianthous

I'm having the same issue. I'm really new to googleapiclient, so I'm not sure if I'm just missing something in my understanding. I have something very similar to what you have (code for work, so I can't share), and that matches examples I've found in the docs and elsewhere.

lawrencek1992 avatar Dec 01 '22 03:12 lawrencek1992