# Path: prestans/ext/appengine.py
# class AppEngineAuthContextProvider(auth.Base):
#     """
#     Provides Authentication Context for Google's AppEngine Environment
# 
#     auth.AuthContextProvider implementation for Google AppEngine, uses google.appengine.api.users
#     to determine logged in users and return a reference to the current user.
# 
#     Refer to decorators in handlers package for more information.
#     """
# 
#     def is_authenticated_user(self):
#         """
#         Override is_authenticated_user for Google AppEngine
#         Uses google.appengine.api.users method get_current_user to check if a user is logged in
#         """
#         from google.appengine.api import users
#         return users.get_current_user() is not None
# 
#     def get_current_user(self):
#         """
#         Override get_current_user for Google AppEngine
#         Checks for oauth capable request first, if this fails fall back to standard users API
#         """
#         from google.appengine.api import users
# 
#         if _IS_DEVELOPMENT_SERVER:
#             return users.get_current_user()
#         else:
#             from google.appengine.api import oauth
# 
#             try:
#                 user = oauth.get_current_user()
#             except oauth.OAuthRequestError:
#                 user = users.get_current_user()
#             return user
# 
# Path: prestans/ext/appengine.py
# class AppEngineMemcacheProvider(cache.Base):
#     """
#     Provides a wrapper on AppEngine's memcache implementation.
#     """
#     
#     def get(self, key, namespace=None, for_cas=False):
#         from google.appengine.api import memcache
#         return memcache.get(key, namespace, for_cas)
#     
#     def set(self, key, value, time=0, min_compress_len=0, namespace=None):
#         from google.appengine.api import memcache
#         return memcache.set(key, value, time, min_compress_len, namespace)
#         
#     def add(self, key, value, time=0, min_compress_len=0, namespace=None):
#         from google.appengine.api import memcache
#         return memcache.add(key, value, time, min_compress_len, namespace)
#         
#     def delete(self, key, seconds=0, namespace=None):
#         from google.appengine.api import memcache
#         return memcache.delete(key, seconds, namespace)
#         
#     def flush_all(self):
#         from google.appengine.api import memcache
#         return memcache.flush_all()


from mock import MagicMock, patch
from prestans.ext.appengine import AppEngineAuthContextProvider
from prestans.ext.appengine import AppEngineMemcacheProvider
import unittest
        import prestans.ext.appengine
        import prestans.ext.appengine

    def setUp(self):
        self.gae_mock = MagicMock()
        self.gae_mock.google.appengine.api.memcache.get.return_value = "value"
        self.gae_mock.google.appengine.api.memcache.set.return_value = True
        self.gae_mock.google.appengine.api.memcache.add.return_value = True
        self.gae_mock.google.appengine.api.memcache.delete.return_value = True
        self.gae_mock.google.appengine.api.memcache.flush_all.return_value = True

        gae_modules = {
            "google": self.gae_mock.google,
            "google.appengine": self.gae_mock.google.appengine,
            "google.appengine.api": self.gae_mock.google.appengine.api
        }

        self.module_patcher = patch.dict('sys.modules', gae_modules)
        self.module_patcher.start()

    def tearDown(self):
        self.module_patcher.stop()

    def test_get(self):
        memcache = AppEngineMemcacheProvider()
        self.assertEqual(memcache.get("key"), "value")
        self.gae_mock.google.appengine.api.memcache.get.assert_called_with("key", None, False)

        self.assertEqual(memcache.get("key", "namespace", True), "value")
        self.gae_mock.google.appengine.api.memcache.get.assert_called_with("key", "namespace", True)

    def test_set(self):

# Path: prestans/ext/appengine.py
# class AppEngineAuthContextProvider(auth.Base):
#     """
#     Provides Authentication Context for Google's AppEngine Environment
# 
#     auth.AuthContextProvider implementation for Google AppEngine, uses google.appengine.api.users
#     to determine logged in users and return a reference to the current user.
# 
#     Refer to decorators in handlers package for more information.
#     """
# 
#     def is_authenticated_user(self):
#         """
#         Override is_authenticated_user for Google AppEngine
#         Uses google.appengine.api.users method get_current_user to check if a user is logged in
#         """
#         from google.appengine.api import users
#         return users.get_current_user() is not None
# 
#     def get_current_user(self):
#         """
#         Override get_current_user for Google AppEngine
#         Checks for oauth capable request first, if this fails fall back to standard users API
#         """
#         from google.appengine.api import users
# 
#         if _IS_DEVELOPMENT_SERVER:
#             return users.get_current_user()
#         else:
#             from google.appengine.api import oauth
# 
#             try:
#                 user = oauth.get_current_user()
#             except oauth.OAuthRequestError:
#                 user = users.get_current_user()
#             return user
# 
# Path: prestans/ext/appengine.py
# class AppEngineMemcacheProvider(cache.Base):
#     """
#     Provides a wrapper on AppEngine's memcache implementation.
#     """
#     
#     def get(self, key, namespace=None, for_cas=False):
#         from google.appengine.api import memcache
#         return memcache.get(key, namespace, for_cas)
#     
#     def set(self, key, value, time=0, min_compress_len=0, namespace=None):
#         from google.appengine.api import memcache
#         return memcache.set(key, value, time, min_compress_len, namespace)
#         
#     def add(self, key, value, time=0, min_compress_len=0, namespace=None):
#         from google.appengine.api import memcache
#         return memcache.add(key, value, time, min_compress_len, namespace)
#         
#     def delete(self, key, seconds=0, namespace=None):
#         from google.appengine.api import memcache
#         return memcache.delete(key, seconds, namespace)
#         
#     def flush_all(self):
#         from google.appengine.api import memcache
#         return memcache.flush_all()


# Path: tests/ext/test_appengine.py
from mock import MagicMock, patch
from prestans.ext.appengine import AppEngineAuthContextProvider
from prestans.ext.appengine import AppEngineMemcacheProvider
import unittest
        import prestans.ext.appengine
        import prestans.ext.appengine


    def setUp(self):
        self.gae_mock = MagicMock()
        self.gae_mock.google.appengine.api.memcache.get.return_value = "value"
        self.gae_mock.google.appengine.api.memcache.set.return_value = True
        self.gae_mock.google.appengine.api.memcache.add.return_value = True
        self.gae_mock.google.appengine.api.memcache.delete.return_value = True
        self.gae_mock.google.appengine.api.memcache.flush_all.return_value = True

        gae_modules = {
            "google": self.gae_mock.google,
            "google.appengine": self.gae_mock.google.appengine,
            "google.appengine.api": self.gae_mock.google.appengine.api
        }

        self.module_patcher = patch.dict('sys.modules', gae_modules)
        self.module_patcher.start()

    def tearDown(self):
        self.module_patcher.stop()

    def test_get(self):
        memcache = AppEngineMemcacheProvider()
        self.assertEqual(memcache.get("key"), "value")
        self.gae_mock.google.appengine.api.memcache.get.assert_called_with("key", None, False)

        self.assertEqual(memcache.get("key", "namespace", True), "value")
        self.gae_mock.google.appengine.api.memcache.get.assert_called_with("key", "namespace", True)

    def test_set(self):

        memcache = AppEngineMemcacheProvider()