I am writing a test for getting label data from Google Cloud Vision API.
Within the test I am using vcrpy to store the results of my label retrieval.
with vcr.use_cassette(
vcr_cassette_path.as_posix(), record_mode="twice",
match_on=["uri", "method"], decode_compressed_response=True):
labels = GCloudVisionLabelsRetriever().get_labels(self.FILE_PATH.as_posix())
Which ends up calling this block, as defined from Google themselves https://cloud.google.com/vision/docs/labels#detect_labels_in_a_local_image:
def detect_labels_from_path(path: str):
client = vision.ImageAnnotatorClient(
credentials=settings.GCLOUD_CREDENTIALS)
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
response = client.label_detection(image=image)
labels = response.label_annotations
return labels
This is OK for the first time the test runs. The second time the test runs, I get an error saying the reach out to Google is unauthenticated.
I believe that this is because VCR doesn't support gRPC which is what is taking place under the hood.
I wonder if there is some way to mock this, or maybe a package that can deal with gRPC for python tests?