def testbed(): tb = Testbed() tb.activate() tb.init_datastore_v3_stub() tb.init_memcache_stub() yield tb tb.deactivate()
def activate_test_stubs(self, connection): if self.active_stubs == 'test': return os.environ['HTTP_HOST'] = "%s.appspot.com" % appid appserver_opts = connection.settings_dict.get('DEV_APPSERVER_OPTIONS', {}) high_replication = appserver_opts.get('high_replication', False) require_indexes = appserver_opts.get('require_indexes', False) datastore_opts = {'require_indexes': require_indexes} if high_replication: from google.appengine.datastore import datastore_stub_util datastore_opts['consistency_policy'] = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1) if self.testbed is None: from google.appengine.ext.testbed import Testbed self.testbed = Testbed() self.testbed.activate() self.pre_test_stubs = self.active_stubs self.active_stubs = 'test' self.testbed.init_datastore_v3_stub(root_path=PROJECT_DIR, **datastore_opts) self.testbed.init_memcache_stub() self.testbed.init_taskqueue_stub(auto_task_running=True, root_path=PROJECT_DIR) self.testbed.init_urlfetch_stub() self.testbed.init_user_stub() self.testbed.init_xmpp_stub() self.testbed.init_channel_stub()
def setUp(self): TestCase.setUp(self) from google.appengine.ext.testbed import Testbed self.testbed = Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub()
def setUp(self): # First, create an instance of the Testbed class. self.testbed = Testbed() # Then activate the testbed, which prepares the service stubs for use. self.testbed.activate() # Next, declare which service stubs you want to use. #self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub() self.testapp = webtest.TestApp(application()) self.testapi = service
def setUp(self): from google.appengine.ext.testbed import ( TASKQUEUE_SERVICE_NAME, Testbed, ) testbed = Testbed() testbed.activate() self.addCleanup(testbed.deactivate) self.addCleanup(TestAsync_decorate_job.foo_values.clear) testbed.init_taskqueue_stub() self._taskq_service = testbed.get_stub(TASKQUEUE_SERVICE_NAME)
def setUp(self): """Initialize stubs for testing. This initializes the following fields: self.testbed: An App Engine Testbed used for mocking App Engine services. This is activated, and any necessary stubs are initialized. self.testapp: A webtest.TestApp wrapping the CherryPy application. Subclasses that define their own setUp method should be sure to call this one as well. """ self.__users = {} self.__admins = {} self.testbed = Testbed() self.testbed.activate() self.testbed.init_app_identity_stub() self.testbed.init_blobstore_stub() self.testbed.init_datastore_v3_stub() self.testbed.init_files_stub() self.testbed.init_memcache_stub() self.testbed.init_taskqueue_stub() self.testbed.init_user_stub() self.testapp = webtest.TestApp(Application()) # These private keys are not used for anything other than testing. PrivateKey.set_oauth('''-----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,CEB8C6541017AC8B q1SgqAfgHXK5cQvtdIF8rkSlbAS6a92T5tYMVKJIW24giF5cw+1++X7X6S5ECykC /iECExP7WfVlPDVoJMZpWGsYLMPhxncnKfUDICbVgwsO4KKeEv8lYTrvkY1sCZIx kSja/lGAWpyxBnmxwoLh0LbLJBGUxUgn2Uqv/8Iid+w0m3NlgrllV+kOo4gUYF9q bestH4nEQj6F0CeI8VPW0FxzMwn0vreHFBT5hul6xbNdB1vnRcz6ed4FiGXoAB5K /8/Q2qyy1UPe2Hr9IoC6wo4h2kXq7pmhy/rtzU9/gjsGPD33ByavbgHAen0ajY5p RmCx0AGidK9T6/SNoyDD9CMq7ypL+0JWoCeVoAEw2aZqN4rMJNbKMgPH+ajgiAXe AWuMVjWN6uTL5+QJmWQct6a6TF8GPKdTcOZfNIXU5U9drHB2hggLcy6XkCYGjVJv MvLascE4oAtOHnwz7WhrpcmX6F6Fww+TPnFzjk+IGJrnBUnAArEcM13IjiDUgg9B iLuKimwrqasdBBY3Ua3SRMoG8PJoNKdsk1hDGlpxLnqOVUCvPKZuz4QnFusnUJrR kiv+aqVBpZYymMh2Q1MWcogA7rL7LIowAkyLzS8dNwDhyk9jbO+1uoFSHKr5BTNv cMJfCVm8pqhXwCVx3uYnhUzvth7mcEseXh5Dcg1RHka5rCXUz4eVxTkj1u3FOy9o 9jgARPpnDYsXH1lESxmiNZucHa50qI/ezNvQx8CbNa1/+JWoZ77yqM9qnDlXUwDY 1Sxqx9+4kthG9oyCzzUwFvhf1kTEHd0RfIapgjJ16HBQmzLnEPtjPA== -----END RSA PRIVATE KEY-----''') PrivateKey.set_api('not a real API key') self.dont_be_oauth_user()
def testbed(): from google.appengine.ext.testbed import Testbed # create an instance of testbed class testbed = Testbed() # activate the testbed, which prepares the services stub for use testbed.activate() # declare which stubs want to use testbed.init_datastore_v3_stub() testbed.init_memcache_stub() return testbed
def testbed(): from google.appengine.ext.testbed import Testbed # create an instance of testbed class testbed = Testbed() # activate the testbed, which prepares the services stub for use testbed.activate() testbed.setup_env(app_id='debug', overwrite=True) # declare which stubs want to use testbed.init_search_stub() testbed.init_urlfetch_stub() return testbed
def setUp(self): tb = Testbed() tb.activate() tb.init_datastore_v3_stub() tb.init_memcache_stub() tb.init_user_stub() self.testbed = tb self.orig_http = set_http_mock() self.orig_user = set_user_mock() self.current_user = users.get_current_user() self.secret = 'xsrfsecret123' self.cache = CredentialsStore() self.clear_cache()
def setUp(self): unittest.TestCase.setUp(self) try: import webtest except ImportError: import setuptools.command.easy_install as easy_install easy_install.main(["WebTest"]) exit() wsgi_application = webapp.WSGIApplication(paths) self.test_app = webtest.TestApp(wsgi_application) from google.appengine.ext.testbed import Testbed self.testbed = Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub()
def testbed(): testbed = Testbed() testbed.activate() # testbed.setup_env(app_id='_') os.environ['APPLICATION_ID'] = '_' # this is a hack to get things working; `testbed.setup_env` does # not seem to be doing the job # see: # http://einaregilsson.com/unit-testing-model-classes-in-google-app-engine/ # will almost always need datastore for tests that use this fixture testbed.init_datastore_v3_stub() # ndb uses memcache, so stub it as well testbed.init_memcache_stub() # clear in-context memcache before test ndb.get_context().clear_cache() yield testbed ndb.get_context().clear_cache() testbed.deactivate()
def __init__(self): self.testbed = Testbed() self.active_stubs = None self.pre_test_stubs = None
#!/usr/bin/env python # coding: utf-8 import os import logging from dev_appserver import fix_sys_path fix_sys_path() from google.appengine.ext.testbed import Testbed tb = Testbed() tb.activate() os.environ['APPLICATION_ID'] = 'rss-xmpp' tb.init_xmpp_stub() tb.init_datastore_v3_stub() tb.init_urlfetch_stub() from rss_xmpp.main import * from google.appengine.api import xmpp from rss_xmpp import feedcrawler import unittest url = 'http://feeds.feedburner.com/github' class XMPPTestMessage(xmpp.Message): def reply(self, body, message_type="chat", raw_xml=False, send_message=xmpp.send_message):
import unittest import webapp2 from google.appengine.api import memcache from google.appengine.ext import ndb from google.appengine.ext.testbed import Testbed testbed = Testbed() testbed.activate() testbed.init_datastore_v3_stub() testbed.init_memcache_stub() ndb.get_context().clear_cache() import main class AppTest(unittest.TestCase): def setUp(self): ndb.get_context().clear_cache() def test_ok(self): request = webapp2.Request.blank('/ok') response = request.get_response(main.app) self.assertEqual(response.status_int, 200) self.assertEqual(response.body, 'ok')