Skip to content


Subversion checkout URL

You can clone with
Download ZIP
GEA learnination
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Google AppEngine Learnination

  • Learn the basics of writing for AppEngine using python
  • Figure out how to do unit testing on AppEngine
    • Figure out how to load data fixtures for consistent testing.

Unit Testing with AppEngine:

Severalin important links:

Data Fixtures

A number of testing solutions offer the ability to load specific test data into a database before running your tests, so that you can design your test data to test various features and error conditions.

The quick-and-dirty FixureLoader I've written loads data from JSON files into the Google datastore during testing. With the Testbed loaded, this happens without ever touching the network, which means that tests can be run self-contained.

A fixture is a JSON file containing and array of dicts that represent model instances, modeled on Django's fixture loader.

    "model": "greeting",
    "content": "hi",
    "author": "",
    "date": "1971-06-29 04:13:01"
    "model": "greeting",
    "content": "bye",
    "author": "",
    "date": "1971-06-29 04:13:00"

The model property is a lowercase and underscore-delimited classname. "greeting" will get converted to "Greeting", while "foo_bar" will get converted to "FooBar". This model class will be imported and instances of the Model will be created from the JSON data.

When FixtureLoader is instantiated, it will look for a fixtures directory in the same directory as the current file. This is stupid and broken, and will be fixed.


from tests.loader import FixtureLoader
from import ok_, eq_

class TestMyClass(object):
    def setUp(self):
        self.loader = FixtureLoader()  # finds the fixture driectory
        self.loader.load_data()  # loads fixtures into the testbed database

    def test_something(self):
        myobjects_query = SomeObject.gql('WHERE etc')
        myobjects = myobject_query.fetch(10)

        ok_(myobjects)  # not None
        eq_(type(myobjects), list)  # got a list back?

        # etc ...

Followup Links:

Still need to grok how the testbad datastore handles indexes:

Something went wrong with that request. Please try again.