Ejemplo n.º 1
0
 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>')))
Ejemplo n.º 2
0
 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>'))
Ejemplo n.º 3
0
def deserialize1():
    """Deserialises invalid fragments"""
    with assert_exception(ValueError):
        deserialize(fromstring(
            '<boolean>invalid</boolean>'))
    with assert_exception(ValueError):
        deserialize(fromstring(
            '<int>invalid</int>'))
Ejemplo n.º 4
0
def deserialize0():
    """Deserialises an unknown fragment"""
    with assert_exception(ValueError):
        deserialize(fromstring(
            '<object class="unknown">'
                '<void property="a">'
                    '<int>42</int>'
                '</void>'
            '</object>'))
Ejemplo n.º 5
0
 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>'))
Ejemplo n.º 6
0
 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>'))
Ejemplo n.º 7
0
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>')))
Ejemplo n.º 8
0
 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>')))
Ejemplo n.º 9
0
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]
Ejemplo n.º 10
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]))
Ejemplo n.º 11
0
def LicenseData_deserialize():
    """Tests that a LicenseData can be serialised to XML"""
    license_data1 = LicenseData(
        '2014-01-01T00:00:00',
        '2014-01-01T00:00:01',
        '2014-01-01T00:00:01',
        issuer = 'CN=issuer',
        subject = 'subject',
        info = 'some information',
        extra = {'hello': 'world'})
    license_data2 = deserialize(serialize(license_data1))
    assert_eq(
        license_data1.not_before,
        license_data2.not_before)
    assert_eq(
        license_data1.not_after,
        license_data2.not_after)
    assert_eq(
        license_data1.issued,
        license_data2.issued)
    assert_eq(
        license_data1.issuer,
        license_data2.issuer)
    assert_eq(
        license_data1.subject,
        license_data2.subject)
    assert_eq(
        license_data1.info,
        license_data2.info)
    assert_eq(
        license_data1.extra,
        license_data2.extra)
Ejemplo n.º 12
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]))
Ejemplo n.º 13
0
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]))
Ejemplo n.º 14
0
 def test_deserialize(self):
     """Tests that a LicenseData can be serialised to XML"""
     license_data1 = LicenseData('2014-01-01T00:00:00',
                                 '2014-01-01T00:00:01',
                                 '2014-01-01T00:00:01',
                                 issuer='CN=issuer',
                                 subject='subject',
                                 info='some information',
                                 extra={'hello': 'world'})
     license_data2 = deserialize(serialize(license_data1))
     self.assertEqual(license_data1.not_before, license_data2.not_before)
     self.assertEqual(license_data1.not_after, license_data2.not_after)
     self.assertEqual(license_data1.issued, license_data2.issued)
     self.assertEqual(license_data1.issuer, license_data2.issuer)
     self.assertEqual(license_data1.subject, license_data2.subject)
     self.assertEqual(license_data1.info, license_data2.info)
     self.assertEqual(license_data1.extra, license_data2.extra)
Ejemplo n.º 15
0
 def test_deserialize_datetime(self):
     """Deserialises datetime objects"""
     expected = datetime.strptime('2014-01-01 UTC', '%Y-%m-%d %Z')
     self.assertEqual(expected, deserialize(serialize(expected)))
Ejemplo n.º 16
0
def deserialize4():
    """Deserialises datetime objects"""
    expected = datetime.strptime('2014-01-01 UTC', '%Y-%m-%d %Z')
    assert_eq(
        expected,
        deserialize(serialize(expected)))
Ejemplo n.º 17
0
 def test_deserialize_datetime(self):
     """Deserialises datetime objects"""
     expected = datetime.strptime('2014-01-01 UTC', '%Y-%m-%d %Z')
     self.assertEqual(
         expected,
         deserialize(serialize(expected)))
Ejemplo n.º 18
0
 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>'))