views:

98

answers:

2

I run my google app engine application in one of two ways...

  1. Directly by using the application from http://localhost:8080
  2. Or execute unit tests from http://localhost:8080/test

When I create entities by using the application directly, the data is visible in the Development Console (dataStore view).

However, when I execute the unit tests... even if they succeed and I can put() and get() data, the data does not show in the dataStore view. Any idea why I can't see my data? Even though it is there?

Notes:

  • I use GAEUnit for unit tests.
  • the data stored mostly consists of StringProperties().
  • I use Python and run Django on top of the GAE, don't know if that matters.
+2  A: 

Is there a chance your Dev Console DataStore view is looking at a different datastore than your django app is writing to? I had a similar issue with my Django/GAE setup and resolved it by explicitly saying the location of my datastore when starting up the dev server. To start the dev server this way, just go into the directory of your django project and type:

dev_appserver.py --datastore_path=/path/to/datastore/my_datastore --history_path=/path/to/datastore/my_datastore
Spike
I think you may be on to something. I tried this, but added an incorrect path. My application failed (like it should have), but my tests still succeeded, so for some reason my tests seem to use a different datastore path. Will investigate...
willem
Yes, it appears that the GAEUnit initializes its own datastore stub. I don't know if this is the same one the standard google dev service uses. Either way it is initialized with a different app path, so I need to figure out how to point it to the same datastore. Thanks for the help!
willem
You're welcome. I'm glad I could point you in the right direction!
Spike
+1  A: 

GAEUnit creates its own proxy stub datastore, using this code on line 357 of the current '2.0a for django' release:

temp_stub = datastore_file_stub.DatastoreFileStub(
    'GAEUnitDataStore', None, None, trusted=True)

This proxy datastore is only held in memory, so is deleted once the tests finish running. It is also empty when the tests start running, ie it does not contain any data currently in the default development datastore.

You can temporarily modify this to make it write to a file on your development system, eg:

temp_stub = datastore_file_stub.DatastoreFileStub(
    'GAEUnitDataStore', '/path/to/gaeunit.datastore', None, trusted=True)

Then run dev_appserver.py on a different port, eg:

dev_appserver.py --port=8081 --datastore_path=/path/to/gaeunit.datastore /path/to/application/

And then finally, open http://localhost:8081/_ah/admin in a browser to view the contents of the temporary datastore.

Saxon Druce
Awesome, thanks for the tip!
willem