Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 如何在GAE(python)上使用Google云存储的模型上运行本地单元测试_Google App Engine_Google Cloud Storage - Fatal编程技术网

Google app engine 如何在GAE(python)上使用Google云存储的模型上运行本地单元测试

Google app engine 如何在GAE(python)上使用Google云存储的模型上运行本地单元测试,google-app-engine,google-cloud-storage,Google App Engine,Google Cloud Storage,我试图为一个模型编写单元测试,该模型调用存储在google云存储上的文件,但我还没有找到任何关于如何模拟GCS服务进行单元测试的示例 似乎应该有一个我可以使用的,我看到了一些关于gcs的参考文献,但是还没有确定一个我可以使用的例子 以下是我拥有的模型的浓缩/示例版本: import peewee from google.appengine.api import app_identity import cloudstorage class Example(Model): uuid = p

我试图为一个模型编写单元测试,该模型调用存储在google云存储上的文件,但我还没有找到任何关于如何模拟GCS服务进行单元测试的示例

似乎应该有一个我可以使用的,我看到了一些关于gcs的参考文献,但是还没有确定一个我可以使用的例子

以下是我拥有的模型的浓缩/示例版本:

import peewee
from google.appengine.api import app_identity
import cloudstorage

class Example(Model):
    uuid = peewee.CharField(default=uuid4)
    some_property = peewee.CharField()

    @property
    def raw_file_one(self):
        bucket = app_identity.get_default_gcs_bucket_name()
        filename = '/{0}/repo_one/{1}'.format(bucket, self.uuid)
        with cloudstorage.open(filename, 'r') as f:
            return f.read()

    def store_raw_file(self, raw_file_one):
        bucket = app_identity.get_default_gcs_bucket_name()

        filename = '/{0}/stat_doms/{1}'.format(bucket, self.uuid)
        with cloudstorage.open(filename, 'w') as f:
            f.write(raw_file_one)
我将使用以下内容构建测试用例:

import unittest

from google.appengine.ext import testbed    

class TestCase(unittest.TestCase):
    def run(self, *args, **kwargs):
        self.stub_google_services()
        result = super(TestCase, self).run(*args, **kwargs)
        self.unstub_google_services()
        return result

    def stub_google_services(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_all_stubs()

    def unstub_google_services(self):
        self.testbed.deactivate()
进入模块测试,如:

from application.tests.testcase import TestCase
from application.models import Example

class ExampleTest(TestCase):
    def test_store_raw_file(self):
    ...
    [assert something]
我假设我会做一些类似于
blobstore=self.testbed.get_stub('blobstore')
的事情来创建一个我可以对其执行测试的服务(例如
blobstore.CreateBlob(blob_键,image)
),但我在testbed ref文档中没有看到用于GCS的服务


关于如何使用GCS实施单元测试的想法?

我想您正在寻找:

from google.appengine.ext.cloudstorage import cloudstorage_stub
from google.appengine.api.blobstore import blobstore_stub
以及:

blob_stub = blobstore_stub.BlobstoreServiceStub(blob_storage)
storage_stub = cloudstorage_stub.CloudStorageStub(blob_storage)

testbed._register_stub('blobstore', self.blob_stub)
testbed._register_stub("cloudstorage", self.storage_stub)