def create_backend(self, prefix): from stdnet import odm self.namespace = '%s%s-' % (prefix, gen_unique_id()) if self.connection_string: server = getdb(self.connection_string, namespace=self.namespace, **self.backend_params()) self.backend = server yield server.flush() self.mapper = odm.Router(self.backend) for model in self.models: self.mapper.register(model)
def setUpClass(cls): if not cls.models and cls.model: cls.models = (cls.model,) if not cls.model and cls.models: cls.model = cls.models[0] cls.namespace = 'stdnet-test-%s.' % gen_unique_id() if cls.connection_string: server = getdb(cls.connection_string, namespace=cls.namespace, **cls.backend_params()) cls.backend = server if server.name == 'redis': r = server.client.script_flush() if isinstance(r, BackendRequest): return r.add_callback(lambda r: cls.clear_all()) return cls.clear_all()
def tempkey(self, meta, name=None): return self.basekey(meta, TMP, name if name is not None else gen_unique_id())
def get_client(self, prefix=None): prefix = prefix or gen_unique_id() c = self.backend.client.prefixed(prefix + self.namespace) if c.prefix not in self.clients: self.clients[c.prefix] = c return self.clients[c.prefix]
def _pre_setup(self): if not self.models and self.model: self.models = (self.model,) self.prefix = 'stdnet-test-'+gen_unique_id()+'.' self.backend = getdb(prefix = self.prefix) return self.backend.flush(pattern = 'stdnet-test-*')