[英]Make the Google python client library for accessing Google cloud storage hit a stubbed API
I am writing an application that uses Google's python client for GCS. 我正在编写一个使用Google的python客户端进行GCS的应用程序。
https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-python https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-python
I've had no issues using this, until I needed to write my functional tests. 在我需要编写功能测试之前,我没有遇到任何问题。
The way our organization tests integrations like this is to write a simple stub of the API endpoints I hit, and point the Google client library (in this case) to my stub, instead of needing to hit Google's live endpoints. 我们的组织测试这样的集成的方式是编写我点击的API端点的简单存根,并将Google客户端库(在本例中)指向我的存根,而不是需要访问Google的实时端点。
I'm using a service account for authentication and am able to point the client at my stub when fetching a token because it gets that value from the service account's json key that you get when you create the service account. 我正在使用服务帐户进行身份验证,并且在获取令牌时能够将客户端指向我的存根,因为它从您在创建服务帐户时获得的服务帐户的json密钥中获取该值。
What I don't seem able to do is point the client library at my stubbed API instead of making calls directly to Google. 我似乎无法做的是将客户端库指向我的存根API,而不是直接向Google调用。
Some work arounds that I've though of, that I don't like are: - Allow the tests to hit the live endpoints. 我曾经做过的一些我不喜欢的解决办法是: - 允许测试点击实时端点。 - Put in some configuration that toggles using the real Google client library, or a mocked version of the library.
- 使用真正的Google客户端库或模拟版本的库进行一些切换。 I'd rather mock the API versus having mock code deployed to production.
我宁愿模仿API而不是将模拟代码部署到生产中。
Any help with this is greatly appreciated. 非常感谢任何帮助。
I've made some research and it seems like there's nothing supported specifically for Cloud Storage using python. 我已经做了一些研究,似乎没有什么专门支持使用python的云存储。 I found this GitHub issue entry with a related discussion, but for go.
我发现这个GitHub问题条目与相关的讨论,但为了去。
I think you can open a public issue tracker asking for this functionality. 我想你可以打开一个公共问题跟踪器来询问这个功能。 I'm afraid by now it's easier to keep using your second workaround.
我现在害怕继续使用你的第二种解决方法更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.