Posted By

manatlan on 09/12/09


Tagged

python web GAE


Versions (?)

Stub for GAE (for unittests)


 / Published in: Python
 

  1. import sys
  2. import os
  3.  
  4. APP_ID = u'aeweb_stub'
  5. AUTH_DOMAIN = 'gmail.com'
  6. LOGGED_IN_USER = '[email protected]' # set to '' for no logged in user
  7.  
  8. from google.appengine.api import apiproxy_stub_map
  9. from google.appengine.api import datastore_file_stub
  10. from google.appengine.api import mail_stub
  11. from google.appengine.api import urlfetch_stub
  12. from google.appengine.api import user_service_stub
  13. from google.appengine.api.memcache import memcache_stub
  14.  
  15. # Start with a fresh api proxy.
  16. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
  17.  
  18. # Use a fresh stub datastore.
  19. stub = datastore_file_stub.DatastoreFileStub(APP_ID, '/dev/null', '/dev/null')
  20. apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)
  21. os.environ['APPLICATION_ID'] = APP_ID
  22.  
  23. # Use a fresh stub UserService.
  24. apiproxy_stub_map.apiproxy.RegisterStub('user',
  25. user_service_stub.UserServiceStub())
  26. os.environ['AUTH_DOMAIN'] = AUTH_DOMAIN
  27. os.environ['USER_EMAIL'] = LOGGED_IN_USER
  28.  
  29. # Use a fresh urlfetch stub.
  30. apiproxy_stub_map.apiproxy.RegisterStub(
  31. 'urlfetch', urlfetch_stub.URLFetchServiceStub())
  32.  
  33. # Use a fresh mail stub.
  34. apiproxy_stub_map.apiproxy.RegisterStub(
  35. 'mail', mail_stub.MailServiceStub())
  36.  
  37. # Use a fresh memcache stub.
  38. apiproxy_stub_map.apiproxy.RegisterStub('memcache', memcache_stub.MemcacheServiceStub())

Report this snippet  

You need to login to post a comment.