Source code for tic.development.appengine.server.test

from tic.development.appengine import utils
if utils.in_development():

    import os
    import unittest
    import logging
    from google.appengine.api import apiproxy_stub_map
    from google.appengine.api import datastore_file_stub
    from google.appengine.api import mail_stub
    from google.appengine.api import user_service_stub
    try:
        from google.appengine.api.images import images_stub
    except ImportError:
        print """
        Could not initialize images API; you are likely missing the Python "PIL" module.
        ImportError: No module named _imaging
        """
        
    from google.appengine.api.taskqueue import taskqueue_stub
    from google.appengine.api.memcache import memcache_stub
    from google.appengine.api.xmpp import xmpp_service_stub

    import capabilities


[docs] class AppEngineTest(object):
[docs] def setUp(self, disabled_capabilities=None, disabled_methods=None): """Setup routine for App Engine test cases. Args: disabled_capabilities: A set of (package, capability) tuples defining capabilities that are disabled. disabled_methods: A set of (package, method) tuples defining methods that are disabled. An entry of ('package', '*') in disabled_capabilities is treated the same as finding the method being tested in this set. """ # Set up a new set of stubs for each test self.stub_map = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy = self.stub_map if disabled_capabilities: self.disabled_capabilities = disabled_capabilities else: self.disabled_capabilities = set() if disabled_methods: self.disabled_methods = disabled_methods else: self.disabled_methods = set() capability_stub = capabilities.CapabilityServiceStub( self.disabled_capabilities, self.disabled_methods) self.stub_map.RegisterStub('capability_service', capability_stub)
def _RegisterStub(self, service_name, stub): wrapped_stub = capabilities.CapabilityStubWrapper(stub, self.disabled_capabilities, self.disabled_methods) self.stub_map.RegisterStub(service_name, wrapped_stub)
[docs] class DatastoreTest(AppEngineTest):
[docs] def setUp(self, datastore_file=None, history_file=None, require_indexes=False, **kwargs): super(DatastoreTest, self).setUp(**kwargs) stub = datastore_file_stub.DatastoreFileStub( os.environ['APPLICATION_ID'], datastore_file, history_file, require_indexes) self._RegisterStub('datastore_v3', stub)
[docs] class MemcacheTest(AppEngineTest):
[docs] def setUp(self, **kwargs): super(MemcacheTest, self).setUp(**kwargs) stub = memcache_stub.MemcacheServiceStub() self._RegisterStub('memcache', stub)
[docs] class UsersTest(AppEngineTest):
[docs] def setUp(self, user_email=None, user_is_admin=False, **kwargs): super(UsersTest, self).setUp(**kwargs) stub = user_service_stub.UserServiceStub() self._RegisterStub('user', stub) self.SetUser(user_email, user_is_admin)
[docs] def SetUser(self, user_email, user_is_admin=False): os.environ['USER_EMAIL'] = user_email os.environ['USER_IS_ADMIN'] = user_is_admin # TODO: Better test-oriented implementations of Mail, XMPP, URLFetch stubs
[docs] class MailTest(AppEngineTest):
[docs] def setUp(self, **kwargs): super(MailTest, self).setUp(**kwargs) stub = mail_stub.MailServiceStub() self._RegisterStub('mail', stub)
[docs] class ImagesTest(AppEngineTest):
[docs] def setUp(self, **kwargs): super(ImagesTest, self).setUp(**kwargs) stub = images_stub.ImagesServiceStub() self._RegisterStub('images', stub)
[docs] class XmppTest(AppEngineTest):
[docs] def setUp(self, xmpp_log=logging.info, **kwargs): super(XmppTest, self).setUp(**kwargs) stub = xmpp_service_stub.XmppServiceStub(log=xmpp_log) self._RegisterStub('xmpp', stub)
[docs] class TaskQueueTest(AppEngineTest):
[docs] def setUp(self, **kwargs): super(XmppTest, self).setUp(**kwargs) stub = taskqueue_stub.TaskQueueServiceStub() self._RegisterStub('taskqueue', self)
[docs] def setup_local_datastore_service(): """ """ d = DatastoreTest() d.setUp()
[docs] def main(app_id, auth_domain='gmail.com', server_software='Development/1.0 (AppEngineTest)'): os.environ['APPLICATION_ID'] = app_id os.environ['AUTH_DOMAIN'] = auth_domain os.environ['SERVER_SOFTWARE'] = server_software unittest.main()