Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically generate indexes with app engine unit tests

Is there a way to get local unit tests with google.appengine.ext.testbed to automatically generate indexes the same way the dev server does? I've tried the following which doesn't seem to work:

from google.appengine.tools import dev_appserver_index

def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_datastore_v3_stub(require_indexes=True)
    dev_appserver_index.SetupIndexes(None, root_directory)
    dev_appserver_index.IndexYamlUpdater(root_directory).UpdateIndexYaml()

I've tried adding the dev_appserver_index bits to both setUp() and tearDown(). I've tried initializing the datastore_v3_stub with require_indexes=True and require_indexes=False. Nothing seems to work.

like image 462
user2839315 Avatar asked Dec 06 '25 04:12

user2839315


1 Answers

You must call the init_datastore_v3_stub method with a root_path option as below:

def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_datastore_v3_stub(root_path="your-root-path")

The root_path is path of a directory that exists a app.yaml file.

It raises NeedIndexError, if you set the require_indexes option to True.

like image 83
ENDOH takanao Avatar answered Dec 07 '25 17:12

ENDOH takanao