Exemplo n.º 1
0
 def test_prepare_is_already_unicode(self):
     message = u"the quick brown fox"
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer="json")
     m, ctype, cencoding = p._prepare(message, content_type="text/plain")
     self.assertEqual(m, message.encode("utf-8"))
     self.assertEqual(ctype, "text/plain")
     self.assertEqual(cencoding, "utf-8")
     m, ctype, cencoding = p._prepare(message, content_type="text/plain",
                                     content_encoding="utf-8")
     self.assertEqual(m, message.encode("utf-8"))
     self.assertEqual(ctype, "text/plain")
     self.assertEqual(cencoding, "utf-8")
Exemplo n.º 2
0
 def test_prepare_is_already_unicode(self):
     message = u'the quick brown fox'
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer='json')
     m, ctype, cencoding = p._prepare(message, content_type='text/plain')
     self.assertEqual(m, message.encode('utf-8'))
     self.assertEqual(ctype, 'text/plain')
     self.assertEqual(cencoding, 'utf-8')
     m, ctype, cencoding = p._prepare(message, content_type='text/plain',
                                     content_encoding='utf-8')
     self.assertEqual(m, message.encode('utf-8'))
     self.assertEqual(ctype, 'text/plain')
     self.assertEqual(cencoding, 'utf-8')
Exemplo n.º 3
0
 def test_prepare_custom_content_type(self):
     message = "the quick brown fox".encode("utf-8")
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer="json")
     m, ctype, cencoding = p._prepare(message, content_type="custom")
     self.assertEqual(m, message)
     self.assertEqual(ctype, "custom")
     self.assertEqual(cencoding, "binary")
     m, ctype, cencoding = p._prepare(message, content_type="custom",
                                      content_encoding="alien")
     self.assertEqual(m, message)
     self.assertEqual(ctype, "custom")
     self.assertEqual(cencoding, "alien")
Exemplo n.º 4
0
 def test_prepare_custom_content_type(self):
     message = 'the quick brown fox'.encode('utf-8')
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer='json')
     m, ctype, cencoding = p._prepare(message, content_type='custom')
     self.assertEqual(m, message)
     self.assertEqual(ctype, 'custom')
     self.assertEqual(cencoding, 'binary')
     m, ctype, cencoding = p._prepare(message, content_type='custom',
                                      content_encoding='alien')
     self.assertEqual(m, message)
     self.assertEqual(ctype, 'custom')
     self.assertEqual(cencoding, 'alien')
Exemplo n.º 5
0
 def test_prepare_is_already_unicode(self):
     message = u"the quick brown fox"
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer="json")
     m, ctype, cencoding = p._prepare(message, content_type="text/plain")
     self.assertEqual(m, message.encode("utf-8"))
     self.assertEqual(ctype, "text/plain")
     self.assertEqual(cencoding, "utf-8")
     m, ctype, cencoding = p._prepare(message,
                                      content_type="text/plain",
                                      content_encoding="utf-8")
     self.assertEqual(m, message.encode("utf-8"))
     self.assertEqual(ctype, "text/plain")
     self.assertEqual(cencoding, "utf-8")
Exemplo n.º 6
0
 def test_prepare_custom_content_type(self):
     message = "the quick brown fox".encode("utf-8")
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer="json")
     m, ctype, cencoding = p._prepare(message, content_type="custom")
     self.assertEqual(m, message)
     self.assertEqual(ctype, "custom")
     self.assertEqual(cencoding, "binary")
     m, ctype, cencoding = p._prepare(message,
                                      content_type="custom",
                                      content_encoding="alien")
     self.assertEqual(m, message)
     self.assertEqual(ctype, "custom")
     self.assertEqual(cencoding, "alien")
Exemplo n.º 7
0
 def test_prepare(self):
     message = {u"the quick brown fox": u"jumps over the lazy dog"}
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer="json")
     m, ctype, cencoding = p._prepare(message, headers={})
     self.assertDictEqual(message, anyjson.loads(m))
     self.assertEqual(ctype, "application/json")
     self.assertEqual(cencoding, "utf-8")
Exemplo n.º 8
0
 def test_prepare(self):
     message = {u"the quick brown fox": u"jumps over the lazy dog"}
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer="json")
     m, ctype, cencoding = p._prepare(message, headers={})
     self.assertDictEqual(message, anyjson.loads(m))
     self.assertEqual(ctype, "application/json")
     self.assertEqual(cencoding, "utf-8")
Exemplo n.º 9
0
 def test_prepare(self):
     message = {u'the quick brown fox': u'jumps over the lazy dog'}
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer='json')
     m, ctype, cencoding = p._prepare(message, headers={})
     self.assertDictEqual(message, anyjson.loads(m))
     self.assertEqual(ctype, 'application/json')
     self.assertEqual(cencoding, 'utf-8')
Exemplo n.º 10
0
 def test_prepare_compression(self):
     message = {u"the quick brown fox": u"jumps over the lazy dog"}
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer="json")
     headers = {}
     m, ctype, cencoding = p._prepare(message, compression="zlib",
                                      headers=headers)
     self.assertEqual(ctype, "application/json")
     self.assertEqual(cencoding, "utf-8")
     self.assertEqual(headers["compression"], "application/x-gzip")
     self.assertEqual(simplejson.loads(m.decode("zlib")), message)
Exemplo n.º 11
0
 def test_prepare_compression(self):
     message = {u'the quick brown fox': u'jumps over the lazy dog'}
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer='json')
     headers = {}
     m, ctype, cencoding = p._prepare(message, compression='zlib',
                                      headers=headers)
     self.assertEqual(ctype, 'application/json')
     self.assertEqual(cencoding, 'utf-8')
     self.assertEqual(headers['compression'], 'application/x-gzip')
     import zlib
     self.assertEqual(anyjson.loads(
                         zlib.decompress(m).decode('utf-8')), message)
Exemplo n.º 12
0
 def test_prepare_compression(self):
     message = {u"the quick brown fox": u"jumps over the lazy dog"}
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer="json")
     headers = {}
     m, ctype, cencoding = p._prepare(message,
                                      compression="zlib",
                                      headers=headers)
     self.assertEqual(ctype, "application/json")
     self.assertEqual(cencoding, "utf-8")
     self.assertEqual(headers["compression"], "application/x-gzip")
     import zlib
     self.assertEqual(anyjson.loads(zlib.decompress(m).decode("utf-8")),
                      message)