Esempio n. 1
0
class BaseCase(unittest.TestCase):
    def setUp(self):
        self.file_path = "instance.xml"
        self.converter = ClassModelConverter(simple_factory(), "tns")

    def tearDown(self):
        if os.path.isfile(self.file_path):
            os.unlink(self.file_path)

    def xml(self):
        xml = self.converter.to_xml()
        self.assertTrue(xml)

    def file(self):
        self.converter.to_file(self.file_path)
        self.assertTrue(os.path.isfile(self.file_path))

    def element(self):
        element = self.converter.to_etree()
        self.assertTrue(element)
        tns_tag = '{%s}%s' % \
                  (self.converter.tns, self.converter.instance.__type_name__)
        self.assertEquals(element.tag, tns_tag)

    def remove_ns(self):
        self.converter.include_ns = False
        element = self.converter.to_etree()
        self.assertFalse(element.nsmap)

    def empty_ns(self):
        self.assertRaises(AssertionError, ClassModelConverter,
                          simple_factory(), "")
Esempio n. 2
0
    def test_from_string(self):

        from soaplib.core.util.model_utils import ClassModelConverter

        class Simple(ClassModel):
            number = Integer
            text = String

        class NotSoSimple(ClassModel):

            number_1 = Integer
            number_2 = Integer
            body = Simple


        nss = NotSoSimple()
        nss.number_1 = 100
        nss.number_2 = 1000

        nss.body = Simple()
        nss.body.number = 1
        nss.body.text = "Some Text"

        cmc = ClassModelConverter(nss, "testfromstring", include_ns=False)
        element = cmc.to_etree()

        assert nss.body.number == 1
        assert nss.number_1 == 100

        nss_from_xml = NotSoSimple.from_string(cmc.to_xml())

        assert nss_from_xml.body.number == 1
        assert nss_from_xml.body.text == "Some Text"
        assert nss_from_xml.number_1 == 100
        assert nss_from_xml.number_2 == 1000
Esempio n. 3
0
class BaseCase(unittest.TestCase):

    def setUp(self):
        self.file_path = "instance.xml"
        self.converter = ClassModelConverter(complex_factory(), "complexmodel")

    def tearDown(self):
        if os.path.isfile(self.file_path):
            os.unlink(self.file_path)

    def xml(self):
        xml = self.converter.to_xml()
        self.assertTrue(xml)

    def file(self):
        self.converter.to_file(self.file_path)
        self.assertTrue(os.path.isfile(self.file_path))

    def element(self):
        element =  self.converter.to_etree()
        self.assertTrue(element)
        tns_tag = '{%s}%s' % \
                  (self.converter.tns, self.converter.instance.__type_name__)
        self.assertEquals(element.tag, tns_tag)

    def remove_ns(self):
        self.converter.include_ns = False
        element = self.converter.to_etree()
        self.assertFalse(element.nsmap)

    def empty_ns(self):
        self.assertRaises(AssertionError, ClassModelConverter, simple_factory(), "")
Esempio n. 4
0
    def test_from_string(self):

        from soaplib.core.util.model_utils import ClassModelConverter

        class Simple(ClassModel):
            number = Integer
            text = String

        class NotSoSimple(ClassModel):

            number_1 = Integer
            number_2 = Integer
            body = Simple

        nss = NotSoSimple()
        nss.number_1 = 100
        nss.number_2 = 1000

        nss.body = Simple()
        nss.body.number = 1
        nss.body.text = "Some Text"

        cmc = ClassModelConverter(nss, "testfromstring", include_ns=False)
        element = cmc.to_etree()

        assert nss.body.number == 1
        assert nss.number_1 == 100

        nss_from_xml = NotSoSimple.from_string(cmc.to_xml())

        assert nss_from_xml.body.number == 1
        assert nss_from_xml.body.text == "Some Text"
        assert nss_from_xml.number_1 == 100
        assert nss_from_xml.number_2 == 1000
Esempio n. 5
0
class BaseCase(unittest.TestCase):

    def setUp(self):
        self.file_path = "instance.xml"
        self.converter = ClassModelConverter(complex_factory(), "complexmodel")

    def tearDown(self):
        if os.path.isfile(self.file_path):
            os.unlink(self.file_path)

    def xml(self):
        xml = self.converter.to_xml()
        self.assertTrue(xml)

    def file(self):
        self.converter.to_file(self.file_path)
        self.assertTrue(os.path.isfile(self.file_path))

    def element(self):
        element =  self.converter.to_etree()
        self.assertTrue(element)

        print etree.tostring(element, pretty_print=True)

        tns_tag = '{%s}%s' % \
                  (self.converter.instance.get_namespace(), self.converter.instance.__type_name__)
        self.assertEquals(element.tag, tns_tag)

    def remove_ns(self):
        self.converter.include_ns = False
        element = self.converter.to_etree()
        self.assertFalse(element.nsmap)