Ejemplo n.º 1
0
 def test_set(self):
     Entry.register_response('SET mocket "is awesome!"', OK)
     self.assertTrue(self.rclient.set('mocket', 'is awesome!'))
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(
         Mocket.last_request().data,
         b'*3\r\n$3\r\nSET\r\n$6\r\nmocket\r\n$11\r\nis awesome!\r\n')
Ejemplo n.º 2
0
 def test_hgetall(self):
     h = {b'f1': b'one', b'f2': b'two'}
     Entry.register_response('HGETALL hash', h)
     self.assertEqual(self.rclient.hgetall('hash'), h)
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket._requests[0].data,
                      b'*2\r\n$7\r\nHGETALL\r\n$4\r\nhash\r\n')
Ejemplo n.º 3
0
 def test_hgetall(self):
     h = {b"f1": b"one", b"f2": b"two"}
     Entry.register_response("HGETALL hash", h)
     self.assertEqual(self.rclient.hgetall("hash"), h)
     self.assertEqual(len(Mocket.request_list()), 1)
     self.assertEqual(Mocket.request_list()[0].data,
                      b"*2\r\n$7\r\nHGETALL\r\n$4\r\nhash\r\n")
Ejemplo n.º 4
0
 def test_set(self):
     Entry.register_response('SET mocket "is awesome!"', OK)
     self.assertTrue(self.rclient.set("mocket", "is awesome!"))
     self.assertEqual(len(Mocket.request_list()), 1)
     self.assertEqual(
         Mocket.last_request().data,
         b"*3\r\n$3\r\nSET\r\n$6\r\nmocket\r\n$11\r\nis awesome!\r\n",
     )
Ejemplo n.º 5
0
 def test_lrange(self):
     l = [b'one', b'two', b'three']
     Entry.register_response('LRANGE list 0 -1', l)
     self.assertEqual(self.rclient.lrange('list', 0, -1), l)
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(
         Mocket.last_request().data,
         b'*4\r\n$6\r\nLRANGE\r\n$4\r\nlist\r\n$1\r\n0\r\n$2\r\n-1\r\n')
Ejemplo n.º 6
0
 def test_lrange(self):
     l = [b"one", b"two", b"three"]
     Entry.register_response("LRANGE list 0 -1", l)
     self.assertEqual(self.rclient.lrange("list", 0, -1), l)
     self.assertEqual(len(Mocket.request_list()), 1)
     self.assertEqual(
         Mocket.last_request().data,
         b"*4\r\n$6\r\nLRANGE\r\n$4\r\nlist\r\n$1\r\n0\r\n$2\r\n-1\r\n",
     )
Ejemplo n.º 7
0
 def test_err(self):
     Entry.register_response(
         'INCRBY counter one',
         ERROR('ERR value is not an integer or out of range'))
     self.assertRaises(redis.ResponseError, self.rclient.incr, 'counter',
                       'one')
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(
         Mocket.last_request().data,
         b'*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$3\r\none\r\n')
Ejemplo n.º 8
0
 def test_err(self):
     Entry.register_response(
         "INCRBY counter one",
         ERROR("ERR value is not an integer or out of range"))
     self.assertRaises(redis.ResponseError, self.rclient.incr, "counter",
                       "one")
     self.assertEqual(len(Mocket.request_list()), 1)
     self.assertEqual(
         Mocket.last_request().data,
         b"*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$3\r\none\r\n",
     )
Ejemplo n.º 9
0
 def test_hgetall(self):
     h = {b'f1': b'one', b'f2': b'two'}
     Entry.register_response('HGETALL hash', h)
     self.assertEqual(self.rclient.hgetall('hash'), h)
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket._requests[0].data, b'*2\r\n$7\r\nHGETALL\r\n$4\r\nhash\r\n')
Ejemplo n.º 10
0
 def test_get(self):
     Entry.register_response('GET mocket', 'is awesome!')
     self.assertEqual(self.rclient.get('mocket'), b'is awesome!')
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket._requests[0].data, b'*2\r\n$3\r\nGET\r\n$6\r\nmocket\r\n')
Ejemplo n.º 11
0
 def mocketize_setup(self):
     Entry.register_response('FLUSHDB', OK)
     self.rclient.flushdb()
     self.assertEqual(len(Mocket._requests), 1)
     Mocket.reset()
Ejemplo n.º 12
0
 def test_set(self):
     Entry.register_response('SET mocket "is awesome!"', OK)
     self.assertTrue(self.rclient.set('mocket', 'is awesome!'))
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket.last_request().data, b'*3\r\n$3\r\nSET\r\n$6\r\nmocket\r\n$11\r\nis awesome!\r\n')
Ejemplo n.º 13
0
 def test_get_unicode(self):
     Entry.register_response('GET snowman', '\u2603')
     self.assertEqual(self.rclient.get('snowman'), b'\xe2\x98\x83')
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket.last_request().data, b'*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n')
Ejemplo n.º 14
0
 def test_register_response(self):
     Entry.register_response(command='SET snowman "is ☃!"', response='')
Ejemplo n.º 15
0
 def mocketize_setup(self):
     Entry.register_response('FLUSHDB', OK)
     self.rclient.flushdb()
     self.assertEqual(len(Mocket._requests), 1)
     Mocket.reset()
Ejemplo n.º 16
0
 def test_get(self):
     Entry.register_response('GET mocket', 'is awesome!')
     self.assertEqual(self.rclient.get('mocket'), b'is awesome!')
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket._requests[0].data, b'*2\r\n$3\r\nGET\r\n$6\r\nmocket\r\n')
Ejemplo n.º 17
0
 def test_get_utf8(self):
     Entry.register_response("GET snowman", "☃")
     self.assertEqual(self.rclient.get("snowman"), b"\xe2\x98\x83")
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket._requests[0].data,
                      b"*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n")
Ejemplo n.º 18
0
 def test_err(self):
     Entry.register_response('INCRBY counter one', ERROR('ERR value is not an integer or out of range'))
     self.assertRaises(redis.ResponseError, self.rclient.incr, 'counter', 'one')
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket.last_request().data, b'*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$3\r\none\r\n')
Ejemplo n.º 19
0
 def test_get_unicode(self):
     Entry.register_response('GET snowman', '\u2603')
     self.assertEqual(self.rclient.get('snowman'), b'\xe2\x98\x83')
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket.last_request().data, b'*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n')
Ejemplo n.º 20
0
 def test_get_unicode(self):
     Entry.register_response("GET snowman", "\u2603")
     self.assertEqual(self.rclient.get("snowman"), b"\xe2\x98\x83")
     self.assertEqual(len(Mocket.request_list()), 1)
     self.assertEqual(Mocket.last_request().data,
                      b"*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n")
Ejemplo n.º 21
0
 def test_get(self):
     Entry.register_response("GET mocket", "is awesome!")
     self.assertEqual(self.rclient.get("mocket"), b"is awesome!")
     self.assertEqual(len(Mocket.request_list()), 1)
     self.assertEqual(Mocket.request_list()[0].data,
                      b"*2\r\n$3\r\nGET\r\n$6\r\nmocket\r\n")
Ejemplo n.º 22
0
 def test_lrange(self):
     l = [b'one', b'two', b'three']
     Entry.register_response('LRANGE list 0 -1', l)
     self.assertEqual(self.rclient.lrange('list', 0, -1), l)
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket.last_request().data, b'*4\r\n$6\r\nLRANGE\r\n$4\r\nlist\r\n$1\r\n0\r\n$2\r\n-1\r\n')
Ejemplo n.º 23
0
 def test_raise_exception(self):
     Entry.register_response("INCRBY counter one",
                             socket.error("Mocket rulez!"))
     self.assertRaises(redis.exceptions.ConnectionError, self.rclient.incr,
                       "counter", "one")
Ejemplo n.º 24
0
 def test_register_response(self):
     Entry.register_response(command='SET snowman "is ☃!"', response='')
Ejemplo n.º 25
0
 def test_get_utf8(self):
     Entry.register_response('GET snowman', '☃')
     self.assertEqual(self.rclient.get('snowman'), '☃')
     self.assertEqual(len(Mocket._requests), 1)
     self.assertEqual(Mocket._requests[0].data, '*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n')