Google-cloud-python: Mocking google cloud storage

Created on 17 Aug 2018  路  1Comment  路  Source: googleapis/google-cloud-python

Hi,

I'm trying to test a piece of code that uses the google cloud storage, but there's no emulators for that neither something like to the moto. How can I mock these component?

Thanks.

question storage

Most helpful comment

As you note, there is no emulator for the GCS service (see #4897, #4840): constructing one is not within scope for the google-cloud-storage library project.

"Mocking" is perhaps ambiguous -- to me it implies more of a unit testing context, e.g.:

from google.cloud import storage
import mock

def test_code_using_gcs():
    client = mock.create_autospec(storage.Client)
    # now set 'return_value', etc. on client's methods.

>All comments

As you note, there is no emulator for the GCS service (see #4897, #4840): constructing one is not within scope for the google-cloud-storage library project.

"Mocking" is perhaps ambiguous -- to me it implies more of a unit testing context, e.g.:

from google.cloud import storage
import mock

def test_code_using_gcs():
    client = mock.create_autospec(storage.Client)
    # now set 'return_value', etc. on client's methods.

Was this page helpful?
0 / 5 - 0 ratings