Exemplo n.º 1
0
 def test_unregister(self):
     with self.assertRaises(SerializerNotInstalled):
         unregister("nonexisting")
     registry.encode("foo", serializer="pickle")
     unregister("pickle")
     with self.assertRaises(SerializerNotInstalled):
         registry.encode("foo", serializer="pickle")
     register_pickle()
Exemplo n.º 2
0
 def test_content_type_encoding(self):
     # Using the 'raw' serializer
     self.assertEqual(unicode_string_as_utf8, registry.encode(unicode_string, serializer="raw")[-1])
     self.assertEqual(latin_string_as_utf8, registry.encode(latin_string, serializer="raw")[-1])
     # And again w/o a specific serializer to check the
     # code where we force unicode objects into a string.
     self.assertEqual(unicode_string_as_utf8, registry.encode(unicode_string)[-1])
     self.assertEqual(latin_string_as_utf8, registry.encode(latin_string)[-1])
Exemplo n.º 3
0
 def test_unregister(self):
     self.assertRaises(SerializerNotInstalled,
                       unregister, "nonexisting")
     registry.encode("foo", serializer="pickle")
     unregister("pickle")
     self.assertRaises(SerializerNotInstalled,
                       registry.encode, "foo", serializer="pickle")
     register_pickle()
Exemplo n.º 4
0
 def test_unregister(self):
     with self.assertRaises(SerializerNotInstalled):
         unregister('nonexisting')
     registry.encode('foo', serializer='pickle')
     unregister('pickle')
     with self.assertRaises(SerializerNotInstalled):
         registry.encode('foo', serializer='pickle')
     register_pickle()
Exemplo n.º 5
0
 def test_unregister(self):
     with self.assertRaises(SerializerNotInstalled):
         unregister('nonexisting')
     registry.encode('foo', serializer='pickle')
     unregister('pickle')
     with self.assertRaises(SerializerNotInstalled):
         registry.encode('foo', serializer='pickle')
     register_pickle()
Exemplo n.º 6
0
 def test_unregister(self):
     with self.assertRaises(SerializerNotInstalled):
         unregister("nonexisting")
     registry.encode("foo", serializer="pickle")
     unregister("pickle")
     with self.assertRaises(SerializerNotInstalled):
         registry.encode("foo", serializer="pickle")
     register_pickle()
Exemplo n.º 7
0
 def test_unregister(self):
     self.assertRaises(SerializerNotInstalled, unregister, "nonexisting")
     registry.encode("foo", serializer="pickle")
     unregister("pickle")
     self.assertRaises(SerializerNotInstalled,
                       registry.encode,
                       "foo",
                       serializer="pickle")
     register_pickle()
Exemplo n.º 8
0
 def test_content_type_encoding(self):
     # Using the "raw" serializer
     self.assertEqual(unicode_string_as_utf8,
                      registry.encode(unicode_string, serializer="raw")[-1])
     self.assertEqual(latin_string_as_utf8,
                      registry.encode(latin_string, serializer="raw")[-1])
     # And again w/o a specific serializer to check the
     # code where we force unicode objects into a string.
     self.assertEqual(unicode_string_as_utf8,
                      registry.encode(unicode_string)[-1])
     self.assertEqual(latin_string_as_utf8,
                      registry.encode(latin_string)[-1])
Exemplo n.º 9
0
 def test_json_encode(self):
     self.assertEquals(
         registry.decode(registry.encode(py_data, serializer="json")[-1],
                         content_type='application/json',
                         content_encoding='utf-8'),
         registry.decode(json_data,
                         content_type='application/json',
                         content_encoding='utf-8'))
Exemplo n.º 10
0
 def test_msgpack_decode(self):
     register_msgpack()
     decoded = registry.decode(
                 registry.encode(msgpack_py_data,
                     serializer='msgpack')[-1],
                 content_type='application/x-msgpack',
                 content_encoding='binary')
     self.assertEqual(msgpack_py_data, decoded)
Exemplo n.º 11
0
 def test_msgpack_decode(self):
     register_msgpack()
     decoded = registry.decode(
         registry.encode(msgpack_py_data, serializer='msgpack')[-1],
         content_type='application/x-msgpack',
         content_encoding='binary',
     )
     self.assertEqual(msgpack_py_data, decoded)
Exemplo n.º 12
0
 def test_json_encode(self):
     self.assertEqual(registry.decode(
                           registry.encode(py_data, serializer='json')[-1],
                           content_type='application/json',
                           content_encoding='utf-8'),
                       registry.decode(
                           json_data,
                           content_type='application/json',
                           content_encoding='utf-8'))
Exemplo n.º 13
0
 def test_yaml_encode(self):
     register_yaml()
     self.assertEqual(
         registry.decode(registry.encode(py_data, serializer="yaml")[-1],
                         content_type='application/x-yaml',
                         content_encoding='utf-8'),
         registry.decode(yaml_data,
                         content_type='application/x-yaml',
                         content_encoding='utf-8'))
Exemplo n.º 14
0
 def test_json_encode(self):
     self.assertEqual(
         registry.decode(
             registry.encode(py_data, serializer="json")[-1],
             content_type="application/json",
             content_encoding="utf-8",
         ),
         registry.decode(json_data, content_type="application/json", content_encoding="utf-8"),
     )
Exemplo n.º 15
0
 def test_yaml_encode(self):
     register_yaml()
     self.assertEqual(
         registry.decode(
             registry.encode(py_data, serializer="yaml")[-1],
             content_type="application/x-yaml",
             content_encoding="utf-8",
         ),
         registry.decode(yaml_data, content_type="application/x-yaml", content_encoding="utf-8"),
     )
Exemplo n.º 16
0
 def test_yaml_encode(self):
     register_yaml()
     self.assertEqual(registry.decode(
                           registry.encode(py_data, serializer='yaml')[-1],
                           content_type='application/x-yaml',
                           content_encoding='utf-8'),
                       registry.decode(
                           yaml_data,
                           content_type='application/x-yaml',
                           content_encoding='utf-8'))
Exemplo n.º 17
0
 def test_msgpack_encode(self):
     register_msgpack()
     self.assertEquals(registry.decode(
             registry.encode(msgpack_py_data, serializer="msgpack")[-1],
             content_type='application/x-msgpack',
             content_encoding='binary'),
             registry.decode(
                 msgpack_data,
                 content_type='application/x-msgpack',
                 content_encoding='binary'))
Exemplo n.º 18
0
 def test_yaml_encode(self):
     register_yaml()
     try:
         __import__("yaml")
     except ImportError:
         say("* PyYAML not installed, will not execute related tests.")
         raise SkipTest("PyYAML not installed")
     self.assertEquals(
         registry.decode(registry.encode(py_data, serializer="yaml")[-1],
                         content_type='application/x-yaml',
                         content_encoding='utf-8'),
         registry.decode(yaml_data,
                         content_type='application/x-yaml',
                         content_encoding='utf-8'))
Exemplo n.º 19
0
 def test_yaml_encode(self):
     try:
         import yaml
     except ImportError:
         say("* PyYAML not installed, will not execute related tests.")
         raise SkipTest("PyYAML not installed")
     self.assertEquals(registry.decode(
                           registry.encode(py_data, serializer="yaml")[-1],
                           content_type='application/x-yaml',
                           content_encoding='utf-8'),
                       registry.decode(
                           yaml_data,
                           content_type='application/x-yaml',
                           content_encoding='utf-8'))
Exemplo n.º 20
0
 def test_msgpack_encode(self):
     try:
         import msgpack
     except ImportError:
         say("* msgpack-python not installed, will not execute "
             "related tests.")
         raise SkipTest("msgpack-python not installed")
     self.assertEquals(registry.decode(
             registry.encode(msgpack_py_data, serializer="msgpack")[-1],
             content_type='application/x-msgpack',
             content_encoding='binary'),
             registry.decode(
                 msgpack_data,
                 content_type='application/x-msgpack',
                 content_encoding='binary'))
Exemplo n.º 21
0
 def test_msgpack_encode(self):
     register_msgpack()
     try:
         __import__("msgpack")
     except ImportError:
         say("* msgpack-python not installed, will not execute "
             "related tests.")
         raise SkipTest("msgpack-python not installed")
     self.assertEquals(
         registry.decode(registry.encode(msgpack_py_data,
                                         serializer="msgpack")[-1],
                         content_type='application/x-msgpack',
                         content_encoding='binary'),
         registry.decode(msgpack_data,
                         content_type='application/x-msgpack',
                         content_encoding='binary'))
Exemplo n.º 22
0
 def test_pickle_encode(self):
     self.assertEqual(pickle_data,
                       registry.encode(py_data,
                           serializer='pickle')[-1])
Exemplo n.º 23
0
 def test_pickle_encode(self):
     self.assertEqual(pickle.loads(pickle_data), pickle.loads(registry.encode(py_data, serializer="pickle")[-1]))
Exemplo n.º 24
0
 def test_pickle_encode(self):
     self.assertEquals(pickle_data,
                       registry.encode(py_data, serializer="pickle")[-1])
Exemplo n.º 25
0
 def test_encode_missing(self):
     with self.assertRaises(SerializerNotInstalled):
         registry.encode('foo', serializer='nonexisting')
Exemplo n.º 26
0
 def test_pickle_encode(self):
     self.assertEqual(
         pickle.loads(pickle_data),
         pickle.loads(registry.encode(py_data, serializer='pickle')[-1]),
     )
Exemplo n.º 27
0
 def test_encode__no_serializer(self):
     ctyp, cenc, data = registry.encode(str_to_bytes('foo'))
     self.assertEqual(ctyp, 'application/data')
     self.assertEqual(cenc, 'binary')
Exemplo n.º 28
0
 def test_encode_missing(self):
     with self.assertRaises(SerializerNotInstalled):
         registry.encode('foo', serializer='nonexisting')
Exemplo n.º 29
0
 def test_encode__no_serializer(self):
     ctyp, cenc, data = registry.encode(str_to_bytes('foo'))
     self.assertEqual(ctyp, 'application/data')
     self.assertEqual(cenc, 'binary')