Example #1
0
    def test_generate_form_from_obj(self):
        obj = factory.load('tests/exercise.xml')
        html = factory.generate_form_from_obj(obj)
        self.assertTrue('<form method="POST" id="xmltool-form">' in html)
        self.assertTrue('id="_xml_filename" value=""' in html)

        html = factory.generate_form_from_obj(
            obj,
            form_attrs={'data-action': 'action'})
        self.assertTrue('<form method="POST" data-action="action" '
                        'id="xmltool-form">' in html)

        # Empty object
        dtd_url = 'tests/exercise.dtd'
        dic = dtd_parser.parse(dtd_url=dtd_url)
        obj = dic['Exercise']()
        html = factory.generate_form_from_obj(obj)
        self.assertTrue('<form method="POST" id="xmltool-form">' in html)
        self.assertTrue('id="_xml_filename" value=""' in html)
Example #2
0
 def test_parse(self):
     try:
         dtd_parser.parse()
         assert 0
     except Exception, e:
         self.assertEqual(str(e), 'You didn\'t provide dtd_str nor dtd_url')
Example #3
0
        self.assertEqual(tag.__name__, 'tag')
        self.assertEqual(tag._required, False)
        self.assertEqual(subtag.__name__, 'subtag')
        self.assertEqual(subtag._required, True)
        self.assertEqual(subtag._sub_elements, [])
        self.assertEqual(subtag._parent, tag)

    def test_parse(self):
        try:
            dtd_parser.parse()
            assert 0
        except Exception, e:
            self.assertEqual(str(e), 'You didn\'t provide dtd_str nor dtd_url')

        try:
            dtd_parser.parse(dtd_str=True, dtd_url=True)
            assert 0
        except Exception, e:
            self.assertEqual(str(e),
                             'You should provide either dtd_str or dtd_url')

        dtd_str = '''
            <!ELEMENT Exercise (question)>
            <!ELEMENT question (#PCDATA)>
        '''
        dic = dtd_parser.parse(dtd_str=dtd_str)
        self.assertEqual(len(dic), 2)
        self.assertTrue(issubclass(dic['Exercise'], Element))
        self.assertTrue(issubclass(dic['question'], TextElement))
        old_get_dtd_content = utils.get_dtd_content
        try:
Example #4
0
 def test_parse(self):
     try:
         dtd_parser.parse()
         assert 0
     except Exception, e:
         self.assertEqual(str(e), 'You didn\'t provide dtd_str nor dtd_url')
Example #5
0
        self.assertEqual(tag.__name__, 'tag')
        self.assertEqual(tag._required, False)
        self.assertEqual(subtag.__name__, 'subtag')
        self.assertEqual(subtag._required, True)
        self.assertEqual(subtag._sub_elements, [])
        self.assertEqual(subtag._parent, tag)

    def test_parse(self):
        try:
            dtd_parser.parse()
            assert 0
        except Exception, e:
            self.assertEqual(str(e), 'You didn\'t provide dtd_str nor dtd_url')

        try:
            dtd_parser.parse(dtd_str=True, dtd_url=True)
            assert 0
        except Exception, e:
            self.assertEqual(str(e),
                             'You should provide either dtd_str or dtd_url')

        dtd_str = '''
            <!ELEMENT Exercise (question)>
            <!ELEMENT question (#PCDATA)>
        '''
        dic = dtd_parser.parse(dtd_str=dtd_str)
        self.assertEqual(len(dic), 2)
        self.assertTrue(issubclass(dic['Exercise'], Element))
        self.assertTrue(issubclass(dic['question'], TextElement))
        old_get_dtd_content = utils.get_dtd_content
        try: