Esempio n. 1
0
class BaseCase(unittest.TestCase):
    def setUp(self):
        self.file_path = "instance.xml"
        self.converter = ComplexModelConverter(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, ComplexModelConverter, simple_factory(), "")
Esempio n. 2
0
    def test_from_string(self):

        from rpclib.util.model_utils import ComplexModelConverter

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

        class NotSoSimple(ComplexModel):

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