python-3.x - 需要通过 mock 在本地测试 Python Google Cloud Function
问题描述
我是 Python3 中云函数和模拟测试的新手。
我编写了一个基本的 python 谷歌云函数来将数字字符串存储到谷歌云存储桶中。
from google.cloud import storage
import uuid
import os
file_name = uuid.uuid4().hex
file_content = os.urandom(32)
cloudStorage = storage.Client()
my_folder_name = 'random' + '/' + file_name
bucket = cloudStorage.bucket('TestBucket')
folder = bucket.blob(my_folder_name)
folder.upload_from_string( file_content , content_type="text/plain")
欣赏任何想法或方法来编写单元测试脚本并通过模拟在本地机器上执行它?
解决方案
推荐阅读
- sql - 如何按排序值选择数据顺序并按名称排序NULL
- java - 当 .deleteAll() 方法在其之前执行时,以下测试失败
- javascript - 如何从表格中删除表格行元素的模式?
- c# - Radgrid:引用与 ItemTemplate 中的文本框在同一行上的控件
- assembly - 读取第二个 BMP 文件时汇编程序崩溃
- go - 为什么 Go 根据我声明缓冲区的位置设置不同的内容类型
- git - 可以将 Visual Studio 设置为在我去编辑文件时自动使文件可写吗?
- c - 如何在 x86-64 上将 80 位长 double 的尾数作为 int
- r - 根据 R 中两个表的信息构建稀疏表
- css - 强制图像具有相同的形状,但仍保持响应