0

我正在尝试减少和清理 GAE 数据存储上的数据存储索引,因此我设置了 require_indexes=True。我删除了所有索引并运行了我的单元测试,但测试通过没有问题,并且 GAE SDK 没有对 index.yaml 进行任何更改。为什么会通过????

4

1 回答 1

0

我认为解决方案是 djangoappengine.sb.stubs.activate_test_stubs 需要按如下方式更新以要求和设置索引:

def activate_test_stubs(self, connection):
    if self.active_stubs == 'test':
        return

    os.environ['HTTP_HOST'] = "%s.appspot.com" % appid

    appserver_opts = connection.settings_dict.get('DEV_APPSERVER_OPTIONS', {})

    high_replication = appserver_opts.get('high_replication', False)
    require_indexes = appserver_opts.get('require_indexes', False)

    datastore_opts = {'require_indexes': require_indexes}
    if high_replication:
        from google.appengine.datastore import datastore_stub_util
        datastore_opts['consistency_policy'] = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)

    if self.testbed is None:
        from google.appengine.ext.testbed import Testbed
        self.testbed = Testbed()

    self.testbed.activate()
    self.pre_test_stubs = self.active_stubs
    self.active_stubs = 'test'
    self.testbed.init_datastore_v3_stub(root_path=PROJECT_DIR, **datastore_opts)
    self.testbed.init_memcache_stub()
    self.testbed.init_taskqueue_stub(auto_task_running=True, root_path=PROJECT_DIR)
    self.testbed.init_urlfetch_stub()
    self.testbed.init_user_stub()
    self.testbed.init_xmpp_stub()
    self.testbed.init_channel_stub()

    if require_indexes:
        from google.appengine.tools import dev_appserver_index
        dev_appserver_index.SetupIndexes(None, None)

Alex Burgel 通过这些更改更新了 github 上的 djangoappengine。

于 2014-04-07T13:01:34.123 回答