Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 196233464f
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 84 lines (64 sloc) 2.56 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
import unittest
from google.appengine.ext import testbed
from google.appengine.ext.ndb import model
from google.appengine.ext.ndb import tasklets
import webapp2


def main():
    unittest.main()


#def check_webob_version(minimum_version):
# try:
# # WebOb < 1.0 (App Engine SDK).
# from webob.statusreasons import status_reasons
# from webob.headerdict import HeaderDict
# return 0.96 >= minimum_version
# except ImportError:
# # WebOb >= 1.0.
# from webob.util import status_reasons
# from webob.headers import ResponseHeaders
# return 1.0 <= minimum_version


class BaseTestCase(unittest.TestCase):

    def setUp(self):
        """Set up the test framework.

Service stubs are available for the following services:

- Datastore (use init_datastore_v3_stub)
- Memcache (use init_memcache_stub)
- Task Queue (use init_taskqueue_stub)
- Images (only for dev_appserver; use init_images_stub)
- URL fetch (use init_urlfetch_stub)
- User service (use init_user_stub)
- XMPP (use init_xmpp_stub)
"""
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()

        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()

        # To set custom env vars, pass them as kwargs *after* activate().
        # self.setup_env()

        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_user_stub()

        # Only when testing ndb.
        self.reset_kind_map()
        self.setup_context_cache()

    def tearDown(self):
        # This restores the original stubs so that tests do not interfere
        # with each other.
        self.testbed.deactivate()
        # Clear thread-local variables.
        self.clear_globals()

    def reset_kind_map(self):
        model.Model._reset_kind_map()

    def setup_context_cache(self):
        """Set up the context cache.

We only need cache active when testing the cache, so the default
behavior is to disable it to avoid misleading test results. Override
this when needed.
"""
        ctx = tasklets.get_context()
        ctx.set_cache_policy(False)
        ctx.set_memcache_policy(False)

    def clear_globals(self):
        webapp2._local.__release_local__()

    def register_model(self, name, cls):
        model.Model._kind_map[name] = cls
Something went wrong with that request. Please try again.