Fixtures for testing Google Appengine (GAE) apps
Convenience plugin on top of the testbed the Google Appengine (GAE) SDK already provides.
pip install pytest-beds
After that the plugin is enabled by default. You can use specific fixtures (see below) to activate the Testbed and stub specific services.
The plugin provides fixtures to stub the different services. Usage is therefore simple and straightforward:
# Say, if you create a Foo you hit the database and put some work on queue def test_foo(ndb, taskqueue): foo = Foo.create() assert Foo.query().fetch() == [foo]
List of builtin fixtures:
bed mailer channel urlfetch memcache taskqueue blobstore ndb users
There are two fixtures anonymous and login to handle the users-stub.
Prepares the user stub and returns a function to login actual users:
def test_login(login): # at this point users.get_current_user() will return None login(id=1, firstname.lastname@example.org') # now users.get_current_user() will return a user login.logout() # now users.get_current_user() will return None again
The deferreds fixture inits the taskqueue stub, but returns a useful object, so you can actually run the deferred functions:
def test_work(deferreds): deferred.defer(work, 'to be done') deferreds.consume() assert 'work has been done'