Example #1
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'}))))
Example #2
0
def serialize5():
    """Serialises datetime instances"""
    assert_eq(
        '<object class="java.util.Date">'
            '<long>0</long>'
        '</object>',
        tostring(serialize(datetime.strptime('1970-01-01 UTC', '%Y-%m-%d %Z'))))

    assert_eq(
        '<object class="java.util.Date">'
            '<long>86400000</long>'
        '</object>',
        tostring(serialize(datetime.strptime('1970-01-02 UTC', '%Y-%m-%d %Z'))))
Example #3
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'}))))
Example #4
0
    def test_serialize_datetime(self):
        """Serialises datetime instances"""
        self.assertEqual(
            '<object class="java.util.Date">'
            '<long>0</long>'
            '</object>',
            tostring(serialize(
                datetime.strptime('1970-01-01 UTC', '%Y-%m-%d %Z'))))

        self.assertEqual(
            '<object class="java.util.Date">'
            '<long>86400000</long>'
            '</object>',
            tostring(serialize(
                datetime.strptime('1970-01-02 UTC', '%Y-%m-%d %Z'))))
Example #5
0
    def test_serialize_datetime(self):
        """Serialises datetime instances"""
        self.assertEqual(
            '<object class="java.util.Date">'
            '<long>0</long>'
            '</object>',
            tostring(
                serialize(datetime.strptime('1970-01-01 UTC', '%Y-%m-%d %Z'))))

        self.assertEqual(
            '<object class="java.util.Date">'
            '<long>86400000</long>'
            '</object>',
            tostring(
                serialize(datetime.strptime('1970-01-02 UTC', '%Y-%m-%d %Z'))))
Example #6
0
    def test_serialize_empty_class(self):
        """Serialises an empty class"""
        class empty(object):
            bean_class = 'test.class'

        self.assertEqual('<object class="test.class" />',
                         tostring(serialize(empty())))
Example #7
0
def serialize4():
    """Serialises an object"""
    class test(object):
        bean_class = 'test.class'
        @property
        def z(self):
            return True
        @property
        def last(self):
            return 42
        @property
        def first(self):
            return 'hello world'

    assert_eq(
        '<object class="test.class">'
            '<void property="first">'
                '<string>hello world</string>'
            '</void>'
            '<void property="last">'
                '<int>42</int>'
            '</void>'
            '<void property="z">'
                '<boolean>true</boolean>'
            '</void>'
        '</object>',
        tostring(serialize(test())))
Example #8
0
def value_to_xml1():
    """Tests value_to_xml for a class name"""
    assert_eq(
        '<object class="test">'
            '<tag>value</tag>'
        '</object>',
        tostring(value_to_xml('value', 'tag', 'test')))
Example #9
0
 def test_value_to_xml_with_class(self):
     """Tests value_to_xml for a class name"""
     self.assertEqual(
         '<object class="test">'
         '<tag>value</tag>'
         '</object>',
         tostring(value_to_xml('value', 'tag', 'test')))
Example #10
0
 def test_create_from_name(self):
     """Tests that a name can be created from a cryptography.x509.Name"""
     self.assertEqual(
         '<object class="javax.security.auth.x500.X500Principal">'
         '<string>C=XX,ST=Some-State,L=Madeupville,O=Internet Widgits Pty '
         'Ltd,OU=Loafing dept.</string>'
         '</object>',
         tostring(serialize(Name.from_x509_name(self.certificate.subject))))
Example #11
0
    def test_create_from_list(self):
        """Tests that a name can be created from a list"""
        s = [('CN', '<token>'), ('O', 'organisation')]

        self.assertEqual(
            '<object class="javax.security.auth.x500.X500Principal">'
            '<string>CN=#3Ctoken#3E,O=organisation</string>'
            '</object>', tostring(serialize(Name(s))))
Example #12
0
 def test_create_from_name(self):
     """Tests that a name can be created from a cryptography.x509.Name"""
     self.assertEqual(
         '<object class="javax.security.auth.x500.X500Principal">'
         '<string>C=XX,ST=Some-State,L=Madeupville,O=Internet Widgits Pty '
         'Ltd,OU=Loafing dept.</string>'
         '</object>',
         tostring(serialize(Name.from_x509_name(self.certificate.subject))))
Example #13
0
    def test_serialize_empty_class(self):
        """Serialises an empty class"""
        class empty(object):
            bean_class = 'test.class'

        self.assertEqual(
            '<object class="test.class" />',
            tostring(serialize(empty())))
Example #14
0
def Name_serialize0():
    """Tests that a name can be serialised to XML"""
    s = 'CN=#3Ctoken#3E , O=organisation '

    assert_eq(
        '<object class="javax.security.auth.x500.X500Principal">'
        '<string>CN=#3Ctoken#3E,O=organisation</string>'
        '</object>', tostring(serialize(Name(s))))
Example #15
0
def serialize1():
    """Serialises an empty class"""
    class empty(object):
        bean_class = 'test.class'

    assert_eq(
        '<object class="test.class" />',
        tostring(serialize(empty())))
Example #16
0
    def test_create_from_list(self):
        """Tests that a name can be created from a list"""
        s = [('CN', '<token>'), ('O', 'organisation')]

        self.assertEqual(
            '<object class="javax.security.auth.x500.X500Principal">'
            '<string>CN=#3Ctoken#3E,O=organisation</string>'
            '</object>',
            tostring(serialize(Name(s))))
Example #17
0
    def test_serialize(self):
        """Tests that a name can be serialised to XML"""
        s = 'CN=#3Ctoken#3E , O=organisation '

        self.assertEqual(
            '<object class="javax.security.auth.x500.X500Principal">'
            '<string>CN=#3Ctoken#3E,O=organisation</string>'
            '</object>',
            tostring(serialize(Name(s))))
Example #18
0
    def test_serialize_object(self):
        """Serialises an object"""
        class test(object):
            bean_class = 'test.class'

            @property
            def test_property(self):
                return True

        self.assertEqual(
            '<object class="test.class">'
            '<void property="testProperty">'
            '<boolean>true</boolean>'
            '</void>'
            '</object>', tostring(serialize(test())))
Example #19
0
    def test_serialize_object(self):
        """Serialises an object"""
        class test(object):
            bean_class = 'test.class'

            @property
            def test_property(self):
                return True

        self.assertEqual(
            '<object class="test.class">'
            '<void property="testProperty">'
            '<boolean>true</boolean>'
            '</void>'
            '</object>',
            tostring(serialize(test())))
Example #20
0
 def test_serialize_string(self):
     """Serialises a string"""
     self.assertEqual('<string>hello world</string>',
                      tostring(serialize('hello world')))
Example #21
0
def value_to_xml0():
    """Tests value_to_xml for no class name"""
    assert_eq(
        '<test>value</test>',
        tostring(value_to_xml('value', 'test')))
Example #22
0
 def test_value_to_xml_no_class(self):
     """Tests value_to_xml for no class name"""
     self.assertEqual('<test>value</test>',
                      tostring(value_to_xml('value', 'test')))
Example #23
0
def serialize3():
    """Serialises a string"""
    assert_eq(
        '<string>hello world</string>',
        tostring(serialize('hello world')))
Example #24
0
 def test_value_to_xml_no_class(self):
     """Tests value_to_xml for no class name"""
     self.assertEqual(
         '<test>value</test>',
         tostring(value_to_xml('value', 'test')))
Example #25
0
 def test_serialize_string(self):
     """Serialises a string"""
     self.assertEqual(
         '<string>hello world</string>',
         tostring(serialize('hello world')))
Example #26
0
 def test_value_to_xml_with_class(self):
     """Tests value_to_xml for a class name"""
     self.assertEqual(
         '<object class="test">'
         '<tag>value</tag>'
         '</object>', tostring(value_to_xml('value', 'tag', 'test')))