def test_greet_with_mockcache(): fake_cache = mockcache.Client() hello_svc = worker_factory(HelloWorld, cache=fake_cache) assert hello_svc.greet("Matt") == "Hello Matt!" assert fake_cache.get("Matt") == "Hello Matt!"
def memcache(self): servers = config.get("memcache_servers", None) if servers: return olmemcache.Client(servers) else: web.debug("Could not find memcache_servers in the configuration. Used dummy memcache.") import mockcache return mockcache.Client()
def _get_memcache(self): if self._memcache is None: servers = config.get("memcache_servers") if servers: self._memcache = memcache.Client(servers) else: web.debug("Could not find memcache_servers in the configuration. Used dummy memcache.") import mockcache self._memcache = mockcache.Client() return self._memcache
def memcache(self): servers = config.get("memcache_servers", None) if servers: return olmemcache.Client(servers) else: web.debug("Could not find memcache_servers in the configuration. Used dummy memcache.") try: import mockcache return mockcache.Client() except ImportError: from pymemcache.test.utils import MockMemcacheClient return MockMemcacheClient()
def _get_memcache(self): if self._memcache is None: servers = config.get("memcache_servers") if servers: self._memcache = memcache.Client(servers) else: web.debug("Could not find memcache_servers in the configuration. Used dummy memcache.") try: import mockcache # Only supports legacy Python self._memcache = mockcache.Client() except ImportError: # Python 3 from pymemcache.test.utils import MockMemcacheClient self._memcache = MockMemcacheClient() return self._memcache
def GetMemcacheClient(): if _client in (Client.APP_ENGINE, Client.APP_ENGINE_MOCK): from google.appengine.api import memcache return memcache.Client() elif _client == Client.PYTHON_MEMCACHED: import memcache # Anyone else bothered by this client having all cas calls return success # when CAS support is disabled (i.e. cache_cas=False, the default)!? return memcache.Client(['127.0.0.1:11211'], cache_cas=True) elif _client == Client.MOCKCACHE: import mockcache return mockcache.Client(['127.0.0.1:11211'], cache_cas=True) elif _client == Client.PYLIBMC: # pylibmc is buggy, yields: # "*** glibc detected *** python: double free or corruption" import pylibmc return pylibmc.Client(['127.0.0.1:11211'], behaviors={'cas': True}) else: raise AssertionError('unknown client type')
from django.db.migrations.executor import MigrationExecutor from django.test import TestCase from django.utils import timezone import mockcache as memcache from data_set_manager.models import Assay, Contact, Investigation, Study from factory_boy.django_model_factories import GalaxyInstanceFactory from factory_boy.utils import create_dataset_with_necessary_models from .models import (DataSet, ExtendedGroup, WorkflowEngine, invalidate_cached_object) from .search_indexes import DataSetIndex from .utils import get_aware_local_time cache = memcache.Client(["127.0.0.1:11211"]) class CachingTest(TestCase): """Testing the addition and deletion of cached objects""" def setUp(self): # make some data self.username = self.password = '******' self.user = User.objects.create_user(self.username, '', self.password) self.username1 = self.password1 = 'Cool1' self.user1 = User.objects.create_user(self.username1, '', self.password1) self.public_group_name = ExtendedGroup.objects.public_group().name for index, item in enumerate(range(0, 6)): create_dataset_with_necessary_models(slug="TestSlug%d" % index) # Adding to cache
def _value_for_config(self, config): import mockcache return mockcache.Client(), threading.Lock()