Pregunta

I'm trying to reduce and clean up my datastore indexes on GAE datastore, so I set require_indexes=True. I removed all indexes and ran my unit tests, but the tests pass without an issue and there is no changes made by the GAE SDK to index.yaml. Why is it passing?????

¿Fue útil?

Solución

I think the solution is that djangoappengine.sb.stubs.activate_test_stubs needs to be updated as follows to require and setup the indexes:

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 has updated djangoappengine on github with these changes.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top