def test_deserialize_known_fragment(self): """Deserialises known fragments""" self.assertEqual(True, deserialize(fromstring('<boolean>true</boolean>'))) self.assertEqual(42, deserialize(fromstring('<int>42</int>'))) self.assertEqual( 'hello world', deserialize(fromstring('<string>hello world</string>')))
def deserialize1(): """Deserialises invalid fragments""" with assert_exception(ValueError): deserialize(fromstring( '<boolean>invalid</boolean>')) with assert_exception(ValueError): deserialize(fromstring( '<int>invalid</int>'))
def test_deserialize(self): """Deserialises invalid fragments""" with self.assertRaises(ValueError): deserialize(fromstring( '<boolean>invalid</boolean>')) with self.assertRaises(ValueError): deserialize(fromstring( '<int>invalid</int>'))
def deserialize2(): """Deserialises known fragments""" assert_eq( True, deserialize(fromstring( '<boolean>true</boolean>'))) assert_eq( 42, deserialize(fromstring( '<int>42</int>'))) assert_eq( 'hello world', deserialize(fromstring( '<string>hello world</string>')))
def test_deserialize_known_fragment(self): """Deserialises known fragments""" self.assertEqual( True, deserialize(fromstring( '<boolean>true</boolean>'))) self.assertEqual( 42, deserialize(fromstring( '<int>42</int>'))) self.assertEqual( 'hello world', deserialize(fromstring( '<string>hello world</string>')))
def deserialize3(): """Deserialises an object using constructor""" global _DESERIALIZER_CLASSES class_name = 'test.class' try: @bean_class(class_name) class test(object): @property def a(self): return self._a def __init__(self, a): self._a = a o = deserialize(fromstring( '<object class="test.class">' '<void property="a">' '<string>hello world</string>' '</void>' '</object>')) assert_eq('hello world', o.a) assert_eq(test, o.__class__) finally: del _DESERIALIZER_CLASSES[class_name]
def test_to_document(self): """Tests that todocument creates a valid XML document""" expected = 'hello world' self.assertEqual( expected, deserialize(fromstring(to_document(serialize(expected)))[0]))
def deserialize0(): """Deserialises an unknown fragment""" with assert_exception(ValueError): deserialize(fromstring( '<object class="unknown">' '<void property="a">' '<int>42</int>' '</void>' '</object>'))
def test_deserialize_unknown_fragment(self): """Deserialises an unknown fragment""" with self.assertRaises(ValueError): deserialize(fromstring( '<object class="unknown">' '<void property="a">' '<int>42</int>' '</void>' '</object>'))
def test_deserialize_unknown_fragment(self): """Deserialises an unknown fragment""" with self.assertRaises(ValueError): deserialize( fromstring('<object class="unknown">' '<void property="a">' '<int>42</int>' '</void>' '</object>'))
def to_document0(): """Tests that to_document creates a valid XML document""" expected = 'hello world' assert_eq( expected, deserialize( fromstring( to_document( serialize(expected))) [0]))
def test_to_document(self): """Tests that todocument creates a valid XML document""" expected = 'hello world' self.assertEqual( expected, deserialize( fromstring( to_document( serialize(expected))) [0]))
def test_serialize(self): """Tests that a LicenseData can be serialised to XML""" expected = tostring( fromstring( '<object class="de.schlichtherle.license.LicenseContent">' '<void property="consumerType"><string /></void>' '<void property="extra">' '<string>{"hello": "world"}</string>' '</void>' '<void property="holder">' '<object class="javax.security.auth.x500.X500Principal">' '<string>CN=Unknown</string>' '</object>' '</void>' '<void property="info">' '<string>some information</string>' '</void>' '<void property="issued">' '<object class="java.util.Date">' '<long>1388534401000</long>' '</object>' '</void>' '<void property="issuer">' '<object class="javax.security.auth.x500.X500Principal">' '<string>CN=issuer</string>' '</object>' '</void>' '<void property="notAfter">' '<object class="java.util.Date">' '<long>1388534401000</long>' '</object>' '</void>' '<void property="notBefore">' '<object class="java.util.Date">' '<long>1388534400000</long>' '</object>' '</void>' '<void property="subject">' '<string>CN=subject</string>' '</void>' '</object>')) self.assertEqual( expected, tostring( serialize( LicenseData('2014-01-01T00:00:00', '2014-01-01T00:00:01', '2014-01-01T00:00:01', issuer='CN=issuer', subject='CN=subject', info='some information', extra={'hello': 'world'}))))
def test_serialize(self): """Tests that a LicenseData can be serialised to XML""" expected = tostring(fromstring( '<object class="de.schlichtherle.license.LicenseContent">' '<void property="consumerType"><string /></void>' '<void property="extra">' '<string>{"hello": "world"}</string>' '</void>' '<void property="holder">' '<object class="javax.security.auth.x500.X500Principal">' '<string>CN=Unknown</string>' '</object>' '</void>' '<void property="info">' '<string>some information</string>' '</void>' '<void property="issued">' '<object class="java.util.Date">' '<long>1388534401000</long>' '</object>' '</void>' '<void property="issuer">' '<object class="javax.security.auth.x500.X500Principal">' '<string>CN=issuer</string>' '</object>' '</void>' '<void property="notAfter">' '<object class="java.util.Date">' '<long>1388534401000</long>' '</object>' '</void>' '<void property="notBefore">' '<object class="java.util.Date">' '<long>1388534400000</long>' '</object>' '</void>' '<void property="subject">' '<string>CN=subject</string>' '</void>' '</object>')) self.assertEqual( expected, tostring(serialize(LicenseData( '2014-01-01T00:00:00', '2014-01-01T00:00:01', '2014-01-01T00:00:01', issuer='CN=issuer', subject='CN=subject', info='some information', extra={'hello': 'world'}))))
def test_deserialize(self): """Deserialises invalid fragments""" with self.assertRaises(ValueError): deserialize(fromstring('<boolean>invalid</boolean>')) with self.assertRaises(ValueError): deserialize(fromstring('<int>invalid</int>'))