How To Mock Google Cloud Storage Bucket And Link It To Client Object?
I have a function in cloud run and trying to test using mock in Python. How can I mock bucket with a blob and attach it to storage client? Assert fails and it's displaying output i
Solution 1:
def test_read_sql(self):
storage_client = mock.create_autospec(storage.Client)
mock_bucket = mock.create_autospec(storage.Bucket)
mock_blob = mock.create_autospec(storage.Blob)
mock_bucket.return_value = mock_blob
storage_client.get_bucket.return_value = mock_bucket
mock_bucket.get_blob.return_value = mock_blob
mock_blob.download_as_string.return_value.decode.return_value = "file_content"
read_content = main.read_sql(storage_client, 'test_bucket', 'test_blob')
assert read_content == 'file_content'
Post a Comment for "How To Mock Google Cloud Storage Bucket And Link It To Client Object?"