Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
 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()
Exemplo n.º 4
0
 def tempkey(self, meta, name=None):
     return self.basekey(meta, TMP,
                         name if name is not None else gen_unique_id())
Exemplo n.º 5
0
 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]
Exemplo n.º 6
0
 def tempkey(self, meta, name=None):
     return self.basekey(meta, TMP, name if name is not None else
                         gen_unique_id())
Exemplo n.º 7
0
 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]
Exemplo n.º 8
0
 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-*')