示例#1
0
 def testValueByte(self):
     b = os.urandom(8)
     v = SimpleModel(code='one', somebytes=b)
     self.assertFalse(is_string(v.somebytes))
     self.assertEqual(v.somebytes, b)
     v.save()
     v = SimpleModel.objects.get(code = 'one')
     self.assertFalse(is_string(v.somebytes))
     self.assertEqual(v.somebytes,b)
示例#2
0
 def testValueByte(self):
     models = self.mapper
     b = os.urandom(8)
     v = SimpleModel(code='sdcscdsc', somebytes=b)
     self.assertFalse(is_string(v.somebytes))
     self.assertEqual(v.somebytes, b)
     yield models.session().add(v)
     v = yield models.simplemodel.get(id=v.id)
     self.assertFalse(is_string(v.somebytes))
     self.assertEqual(v.somebytes, b)
示例#3
0
 def testValueByte(self):
     models = self.mapper
     b = os.urandom(8)
     v = SimpleModel(code='sdcscdsc', somebytes=b)
     self.assertFalse(is_string(v.somebytes))
     self.assertEqual(v.somebytes, b)
     yield models.session().add(v)
     v = yield models.simplemodel.get(id=v.id)
     self.assertFalse(is_string(v.somebytes))
     self.assertEqual(v.somebytes, b)
示例#4
0
 def execute_command(self, command, channels, container, add = True):
     "Execute a publish/subscribe command"
     if is_string(channels):
         channels = [channels]
     if add:
         for c in channels:
             container.add(c)
     else:
         for c in channels:
             try:
                 container.remove(c)
             except KeyError:
                 pass
     if self.connection is None:
         self.connection = self.client.connection_pool.get_connection(
             'pubsub',
             self.shard_hint
             )
     connection = self.connection
     try:
         connection.send_command(command, *channels)
         return self.parse_response()
     except ConnectionError:
         connection.disconnect()
         # Connect manually here. If the Redis server is down, this will
         # fail and raise a ConnectionError as desired.
         connection.connect()
         # resubscribe to all channels and patterns before
         # resending the current command
         for channel in self.channels:
             self.subscribe(channel)
         for pattern in self.patterns:
             self.psubscribe(pattern)
         connection.send_command(command, channels)
         return self.parse_response()
示例#5
0
 def testToJson(self):
     models = self.mapper
     b = os.urandom(8)
     v = yield models.simplemodel.new(code='xxsdcscdsc', somebytes=b)
     data = v.tojson()
     value = data['somebytes']
     self.assertTrue(is_string(value))
     v2 = models.simplemodel.from_base64_data(**data)
     self.assertTrue(v2)
     self.assertEqual(v.somebytes, b)
示例#6
0
 def testToJson(self):
     models = self.mapper
     b = os.urandom(8)
     v = yield models.simplemodel.new(code='xxsdcscdsc', somebytes=b)
     data = v.tojson()
     value = data['somebytes']
     self.assertTrue(is_string(value))
     v2 = models.simplemodel.from_base64_data(**data)
     self.assertTrue(v2)
     self.assertEqual(v.somebytes, b)
示例#7
0
 def testName(self):
     session = self.session()
     qb = dict(((i.name,i) for i in session.query(self.model)))
     qs = session.query(self.model).get_field('name')
     self.assertEqual(qs._get_field, 'name')
     result = qs.all()
     self.assertTrue(result)
     for r in result:
         self.assertTrue(is_string(r))
         qb.pop(r)
     self.assertFalse(qb)
示例#8
0
 def testName(self):
     session = self.session()
     all = yield session.query(self.model).all()
     qb = dict(((i.name, i) for i in all))
     qs = session.query(self.model).get_field('name')
     self.assertEqual(qs._get_field, 'name')
     result = yield qs.all()
     self.assertTrue(result)
     for r in result:
         self.assertTrue(is_string(r))
         qb.pop(r)
     self.assertFalse(qb)
示例#9
0
    def brpop(self, keys, timeout=0):
        """
        RPOP a value off of the first non-empty list
        named in the ``keys`` list.

        If none of the lists in ``keys`` has a value to LPOP, then block
        for ``timeout`` seconds, or until a value gets pushed on to one
        of the lists.

        If timeout is 0, then block indefinitely.
        """
        if is_string(keys):
            keys = [keys]
        else:
            keys = list(keys)
        keys.append(timeout)
        return self.execute_command('BRPOP', *keys)