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(), "")
Exemple #2
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(), "")
Exemple #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)

        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)
Exemple #4
0
class AddedRootElementTestCase(BaseCase):
    def setUp(self):
        self.file_path = "instance.xml"
        self.converter = ClassModelConverter(simple_factory(),
                                             "tns",
                                             include_parent=True,
                                             parent_tag="foo")

    def element(self):
        element = self.converter.to_etree()
        self.assertTrue(element)
        self.assertEquals(element.tag, self.converter.parent_tag)

    def test_simple_xml(self):
        self.xml()

    def test_simple_file(self):
        self.file()

    def test_simple_element(self):
        self.element()

    def test_complex_xml(self):
        self.xml()

    def test_complex_file(self):
        self.file()

    def test_complex_element(self):
        self.element()

    def test_strip_ns(self):
        self.remove_ns()
Exemple #5
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
    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
class AddedRootElementTestCase(BaseCase):
    def setUp(self):
        self.file_path = "instance.xml"
        self.converter = ClassModelConverter(
                simple_factory(),"tns",include_parent=True, parent_tag="foo")

    def element(self):
        element =  self.converter.to_etree()
        self.assertTrue(element)
        self.assertEquals(element.tag, self.converter.parent_tag)

    def test_simple_xml(self):
        self.xml()

    def test_simple_file(self):
        self.file()

    def test_simple_element(self):
        self.element()

    def test_complex_xml(self):
        self.xml()

    def test_complex_file(self):
        self.file()

    def test_complex_element(self):
        self.element()

    def test_strip_ns(self):
        self.remove_ns()