# Copyright 2009 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import sys import os.path import logging import unittest import mocker sys.path.insert(0, os.path.realpath(os.path.dirname( __file__ ) + "/../src")) import settings EXTRA_PATHS = [ settings.APP_ENGINE_PATH, os.path.join(settings.APP_ENGINE_PATH, 'lib', 'antlr3'), os.path.join(settings.APP_ENGINE_PATH, 'lib', 'django'), os.path.join(settings.APP_ENGINE_PATH, 'lib', 'webob'), os.path.join(settings.APP_ENGINE_PATH, 'lib', 'yaml', 'lib'), ] for path in EXTRA_PATHS: realpath = os.path.realpath(path) if os.path.exists(realpath): sys.path.append(realpath) else: logging.critical("Could not find path %s [exists: %s, symlink: %s]" % ( realpath, os.path.exists(realpath), os.path.islink(realpath))) try: 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 urlfetch_stub from google.appengine.api import user_service_stub from google.appengine.api.memcache import memcache_stub except ImportError, e: logging.exception(e) class AppEngineTestCase(mocker.MockerTestCase): def setUp(self): os.environ['APPLICATION_ID'] = 'tests' # Preserve the current apiproxy for tearDown(). self.original_apiproxy = apiproxy_stub_map.apiproxy # Create a stub for the datastore ds_stub = datastore_file_stub.DatastoreFileStub('tests', None, None) # Create a stub for memcace mc_stub = memcache_stub.MemcacheServiceStub() # Create a stub for url fetching uf_stub = urlfetch_stub.URLFetchServiceStub() # Create a stub for sending mail m_stub = mail_stub.MailServiceStub() # Create a new apiproxy and init with stubs apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', ds_stub) apiproxy_stub_map.apiproxy.RegisterStub('memcache', mc_stub) apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', uf_stub) apiproxy_stub_map.apiproxy.RegisterStub('mail', m_stub) def tearDown(self): # Restore stubs for development. apiproxy_stub_map.apiproxy = self.original_apiproxy