Example #1
0
 def test_prepare_is_already_unicode(self):
     message = "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")
Example #2
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")
Example #3
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')
Example #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')
 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')
 def test_prepare_is_already_unicode(self):
     message = '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')
Example #7
0
 def test_prepare_custom_content_type(self):
     message = b'the quick brown fox'
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer='json')
     m, ctype, cencoding = p._prepare(message, content_type='custom')
     assert m == message
     assert ctype == 'custom'
     assert cencoding == 'binary'
     m, ctype, cencoding = p._prepare(message, content_type='custom',
                                      content_encoding='alien')
     assert m == message
     assert ctype == 'custom'
     assert cencoding == 'alien'
Example #8
0
 def test_prepare(self):
     message = {'the quick brown fox': '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')
Example #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')
Example #10
0
 def test_prepare(self):
     message = {'the quick brown fox': 'jumps over the lazy dog'}
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer='json')
     m, ctype, cencoding = p._prepare(message, headers={})
     assert json.loads(m) == message
     assert ctype == 'application/json'
     assert cencoding == 'utf-8'
Example #11
0
 def test_prepare(self):
     message = {'the quick brown fox': 'jumps over the lazy dog'}
     channel = self.connection.channel()
     p = Producer(channel, self.exchange, serializer='json')
     m, ctype, cencoding = p._prepare(message, headers={})
     assert json.loads(m) == message
     assert ctype == 'application/json'
     assert cencoding == 'utf-8'
Example #12
0
 def test_prepare(self):
     message = {"the quick brown fox": "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")
Example #13
0
 def test_prepare_compression(self):
     message = {'the quick brown fox': '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)
     assert ctype == 'application/json'
     assert cencoding == 'utf-8'
     assert headers['compression'] == 'application/x-gzip'
     import zlib
     assert json.loads(zlib.decompress(m).decode('utf-8')) == message
Example #14
0
    def test_prepare_compression(self):
        message = {"the quick brown fox": "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)
Example #15
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)
Example #16
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)