Ejemplo n.º 1
0
class InitTestSuite(TestCase):
    def setUp(self):
        self.maxDiff = None
        self.type_generator = VariableTypesGenerator()

    def test_template_list_not_set(self):
        renderer = BaseRenderer()

        # Loose comparison is enough for this test
        self.assertEqual(len(renderer.templates), 0)

    def test_template_list_is_correct_dict(self):

        template_list = {
            "t1": Template('a'),
            "t2": Template('b'),
            "t3": Template('c')
        }

        base_renderer = BaseRenderer()
        base_renderer.templates.update(template_list)

        renderer = BaseRenderer(template_list)

        self.assertEqual(renderer.templates.keys(),
                         base_renderer.templates.keys())

        for tpl_key in renderer.templates.keys():
            try:
                renderer._load_template(tpl_key)
            except Exception as exc:
                self.fail(exc.message)

    def test_template_list_is_incorrect_dict(self):
        template = None

        try:
            for template in self.type_generator.generate_types_excluding([]):
                template_list = {"wrong": template}

                with self.assertRaises(Exception):
                    renderer = BaseRenderer(template_list)
                    renderer._load_template("wrong")
        except AssertionError as error:
            template_type = str(type(template))
            error.message += ' (template type: ' + template_type + ')'
            raise AssertionError(error.message)

    def test_template_list_not_dict(self):
        template_list = None

        try:
            for template_list in self.type_generator.generate_types_excluding(
                ['dict', 'none']):
                with self.assertRaises(Exception):
                    BaseRenderer(template_list)
        except AssertionError as error:
            template_list_type = str(type(template_list))
            error.message += ' (template_list type: ' + template_list_type + ')'
            raise AssertionError(error.message)
Ejemplo n.º 2
0
    def setUp(self):
        ul_data = join('utils', 'XSDParser', 'tests', 'data', 'renderer',
                       'default', 'ul')
        self.ul_data_handler = DataHandler(ul_data)

        self.types_generator = VariableTypesGenerator()
        self.content = '<li>lorem ipsum</li>'
    def setUp(self):
        buttons_data = join('curate', 'tests', 'data', 'parser', 'utils', 'buttons')
        self.buttons_data_handler = DataHandler(buttons_data)

        self.types_generator = VariableTypesGenerator()
        self.default_tag_id = 'string'

        self.renderer = HtmlRenderer()
class LoadTemplateTestSuite(TestCase):

    def setUp(self):
        self.renderer = BaseRenderer()
        self.type_generator = VariableTypesGenerator()

    def test_key_exists_data_none(self):
        btn_template_path = join('renderer', 'default', 'buttons', 'collapse.html')
        template_list = {
            "btn": loader.get_template(btn_template_path)
        }

        self.renderer.templates.update(template_list)
        self.renderer._load_template('btn')

    def test_key_not_exists(self):
        with self.assertRaises(Exception):
            self.renderer._load_template('unexisting_key')

    def test_key_not_str(self):
        tpl_key = None

        try:
            for tpl_key in self.type_generator.generate_types_excluding(['str', 'unicode']):
                with self.assertRaises(Exception):
                    self.renderer._load_template(tpl_key)
        except AssertionError as error:
            tpl_key_type = str(type(tpl_key))
            error.message += ' (tpl_key type: ' + tpl_key_type + ')'
            raise AssertionError(error.message)

    def test_tpl_data_is_dict(self):
        btn_template_path = join('renderer', 'default', 'buttons', 'add.html')
        template_list = {
            "btn": loader.get_template(btn_template_path)
        }

        self.renderer.templates.update(template_list)
        self.renderer._load_template('btn', {'is_hidden': True})

    def test_tpl_data_not_dict(self):
        tpl_data = None
        btn_template_path = join('renderer', 'default', 'buttons', 'add.html')
        template_list = {
            "btn": loader.get_template(btn_template_path)
        }
        self.renderer.templates.update(template_list)

        try:
            for tpl_data in self.type_generator.generate_types_excluding(['dict', 'none']):
                with self.assertRaises(Exception):
                    self.renderer._load_template('btn', tpl_data)
        except AssertionError as error:
            tpl_data_type = str(type(tpl_data))
            error.message += ' (tpl_data type: ' + tpl_data_type + ')'
            raise AssertionError(error.message)
Ejemplo n.º 5
0
class LoadTemplateTestSuite(TestCase):
    def setUp(self):
        self.renderer = BaseRenderer()
        self.type_generator = VariableTypesGenerator()

    def test_key_exists_data_none(self):
        btn_template_path = join('renderer', 'default', 'buttons',
                                 'collapse.html')
        template_list = {"btn": loader.get_template(btn_template_path)}

        self.renderer.templates.update(template_list)
        self.renderer._load_template('btn')

    def test_key_not_exists(self):
        with self.assertRaises(Exception):
            self.renderer._load_template('unexisting_key')

    def test_key_not_str(self):
        tpl_key = None

        try:
            for tpl_key in self.type_generator.generate_types_excluding(
                ['str', 'unicode']):
                with self.assertRaises(Exception):
                    self.renderer._load_template(tpl_key)
        except AssertionError as error:
            tpl_key_type = str(type(tpl_key))
            error.message += ' (tpl_key type: ' + tpl_key_type + ')'
            raise AssertionError(error.message)

    def test_tpl_data_is_dict(self):
        btn_template_path = join('renderer', 'default', 'buttons', 'add.html')
        template_list = {"btn": loader.get_template(btn_template_path)}

        self.renderer.templates.update(template_list)
        self.renderer._load_template('btn', {'is_hidden': True})

    def test_tpl_data_not_dict(self):
        tpl_data = None
        btn_template_path = join('renderer', 'default', 'buttons', 'add.html')
        template_list = {"btn": loader.get_template(btn_template_path)}
        self.renderer.templates.update(template_list)

        try:
            for tpl_data in self.type_generator.generate_types_excluding(
                ['dict', 'none']):
                with self.assertRaises(Exception):
                    self.renderer._load_template('btn', tpl_data)
        except AssertionError as error:
            tpl_data_type = str(type(tpl_data))
            error.message += ' (tpl_data type: ' + tpl_data_type + ')'
            raise AssertionError(error.message)
Ejemplo n.º 6
0
    def setUp(self):
        input_data = join('utils', 'XSDParser', 'tests', 'data', 'renderer',
                          'default', 'input')
        self.input_data_handler = DataHandler(input_data)

        self.types_generator = VariableTypesGenerator()
        self.renderer = HtmlRenderer()
    def setUp(self):
        input_data = join('curate', 'tests', 'data', 'renderer', 'html',
                          'input')
        self.input_data_handler = DataHandler(input_data)

        self.types_generator = VariableTypesGenerator()
        self.renderer = HtmlRenderer()
    def setUp(self):
        li_data = join('curate', 'tests', 'data', 'renderer', 'default', 'li')
        self.li_data_handler = DataHandler(li_data)

        self.types_generator = VariableTypesGenerator()

        self.content = 'lorem ipsum'
        self.tag_id = '0'
        self.element_tag = 'element'
Ejemplo n.º 9
0
    def setUp(self):
        select_data = join('utils', 'XSDParser', 'tests', 'data', 'renderer', 'default', 'select')
        self.select_data_handler = DataHandler(select_data)

        self.types_generator = VariableTypesGenerator()
        self.select_id = 'select'
        self.select_class = 'select'

        self.renderer = HtmlRenderer()
Ejemplo n.º 10
0
class AbstractInitTestSuite(TestCase):
    def setUp(self):
        self.maxDiff = None
        self.type_generator = VariableTypesGenerator()

    def test_xsd_data_is_schema_element(self):
        xsd_data = SchemaElement()
        xsd_data.tag = "test"

        renderer = AbstractListRenderer(xsd_data)

        self.assertEqual(xsd_data, renderer.data)

    def test_xsd_data_not_schema_element(self):
        xsd_data = None

        try:
            for xsd_data in self.type_generator.generate_types_excluding([]):
                with self.assertRaises(Exception):
                    AbstractListRenderer(xsd_data)
        except AssertionError as error:
            xsd_data_type = str(type(xsd_data))
            error.message += ' (xsd_data type: ' + xsd_data_type + ')'
            raise AssertionError(error.message)

    def test_template_list_not_set(self):
        xsd_data = SchemaElement()
        xsd_data.tag = "test"

        renderer = AbstractListRenderer(xsd_data)

        # Loose comparison is enough for this test
        self.assertEqual(len(renderer.templates), 7)

    def test_template_list_is_correct_dict(self):
        xsd_data = SchemaElement()
        xsd_data.tag = "test"

        template_list = {
            "t1": Template('a'),
            "t2": Template('b'),
            "t3": Template('c')
        }

        base_renderer = AbstractListRenderer(xsd_data)
        base_renderer.templates.update(template_list)

        renderer = AbstractListRenderer(xsd_data, template_list)

        self.assertEqual(renderer.templates.keys(),
                         base_renderer.templates.keys())

    def test_template_list_is_incorrect_dict(self):
        xsd_data = SchemaElement()
        xsd_data.tag = "test"

        template = None

        try:
            for template in self.type_generator.generate_types_excluding([]):
                template_list = {"wrong": template}

                with self.assertRaises(Exception):
                    AbstractListRenderer(xsd_data, template_list)
        except AssertionError as error:
            template_type = str(type(template))
            error.message += ' (template type: ' + template_type + ')'
            raise AssertionError(error.message)

    def test_template_list_not_dict(self):
        xsd_data = SchemaElement()
        xsd_data.tag = "test"

        template_list = None

        try:
            for template_list in self.type_generator.generate_types_excluding(
                ['dict', 'none']):
                with self.assertRaises(Exception):
                    AbstractListRenderer(xsd_data, template_list)
        except AssertionError as error:
            template_list_type = str(type(template_list))
            error.message += ' (template_list type: ' + template_list_type + ')'
            raise AssertionError(error.message)
Ejemplo n.º 11
0
class AbstractRenderUlTestSuite(TestCase):
    def setUp(self):
        ul_data = join('utils', 'XSDParser', 'tests', 'data', 'renderer',
                       'default', 'ul')
        self.ul_data_handler = DataHandler(ul_data)

        self.types_generator = VariableTypesGenerator()
        self.content = '<li>lorem ipsum</li>'

    def test_elem_id_str_chosen_true(self):
        element_id = 'string'
        chosen = True

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(
            result_string,
            render_ul(unicode(self.content), unicode(element_id), chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_str_ch_true')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_elem_id_str_chosen_false(self):
        element_id = 'string'
        chosen = False

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(
            result_string,
            render_ul(unicode(self.content), unicode(element_id), chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_str_ch_false')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_elem_id_empty_str_chosen_true(self):
        element_id = ''
        chosen = True

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(
            result_string,
            render_ul(unicode(self.content), unicode(element_id), chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_empty_ch_true')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_elem_id_empty_str_chosen_false(self):
        element_id = ''
        chosen = False

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(
            result_string,
            render_ul(unicode(self.content), unicode(element_id), chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_empty_ch_false')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_elem_id_none_chosen_true(self):
        element_id = None
        chosen = True

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(result_string,
                         render_ul(unicode(self.content), element_id, chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_none_ch_true')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_elem_id_none_chosen_false(self):
        element_id = 'string'
        chosen = True

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(result_string,
                         render_ul(unicode(self.content), element_id, chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_str_ch_true')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_content_not_str(self):
        content = 'string'
        element_id = 'string'
        chosen = True

        try:
            for content in self.types_generator.generate_types_excluding(
                ['str', 'unicode']):
                with self.assertRaises(Exception):
                    render_ul(content, element_id, chosen)
        except AssertionError as error:
            content_type = str(type(content))
            error.message += ' (content type: ' + content_type + ')'
            raise AssertionError(error.message)

    def test_elem_id_not_str_not_none(self):
        content = 'string'
        element_id = 'string'
        chosen = True

        try:
            for element_id in self.types_generator.generate_types_excluding(
                ['str', 'unicode', 'none']):
                with self.assertRaises(Exception):
                    render_ul(content, element_id, chosen)
        except AssertionError as error:
            element_id_type = str(type(element_id))
            error.message += ' (element_id type: ' + element_id_type + ')'
            raise AssertionError(error.message)

    def test_chosen_not_bool(self):
        content = 'string'
        element_id = 'string'
        chosen = True

        try:
            for chosen in self.types_generator.generate_types_excluding(
                ['bool']):
                with self.assertRaises(Exception):
                    render_ul(content, element_id, chosen)
        except AssertionError as error:
            chosen_type = str(type(chosen))
            error.message += ' (content type: ' + chosen_type + ')'
            raise AssertionError(error.message)
 def setUp(self):
     self.maxDiff = None
     self.type_generator = VariableTypesGenerator()
class AbstractInitTestSuite(TestCase):
    def setUp(self):
        self.maxDiff = None
        self.type_generator = VariableTypesGenerator()

    def test_xsd_data_is_schema_element(self):
        xsd_data = SchemaElement()
        xsd_data.tag = "test"

        renderer = AbstractListRenderer(xsd_data)

        self.assertEqual(xsd_data, renderer.data)

    def test_xsd_data_not_schema_element(self):
        xsd_data = None

        try:
            for xsd_data in self.type_generator.generate_types_excluding([]):
                with self.assertRaises(Exception):
                    AbstractListRenderer(xsd_data)
        except AssertionError as error:
            xsd_data_type = str(type(xsd_data))
            error.message += ' (xsd_data type: ' + xsd_data_type + ')'
            raise AssertionError(error.message)

    def test_template_list_not_set(self):
        xsd_data = SchemaElement()
        xsd_data.tag = "test"

        renderer = AbstractListRenderer(xsd_data)

        # Loose comparison is enough for this test
        self.assertEqual(len(renderer.templates), 7)

    def test_template_list_is_correct_dict(self):
        xsd_data = SchemaElement()
        xsd_data.tag = "test"

        template_list = {
            "t1": Template('a'),
            "t2": Template('b'),
            "t3": Template('c')
        }

        base_renderer = AbstractListRenderer(xsd_data)
        base_renderer.templates.update(template_list)

        renderer = AbstractListRenderer(xsd_data, template_list)

        self.assertEqual(renderer.templates.keys(), base_renderer.templates.keys())

    def test_template_list_is_incorrect_dict(self):
        xsd_data = SchemaElement()
        xsd_data.tag = "test"

        template = None

        try:
            for template in self.type_generator.generate_types_excluding([]):
                template_list = {
                    "wrong": template
                }

                with self.assertRaises(Exception):
                    AbstractListRenderer(xsd_data, template_list)
        except AssertionError as error:
            template_type = str(type(template))
            error.message += ' (template type: ' + template_type + ')'
            raise AssertionError(error.message)

    def test_template_list_not_dict(self):
        xsd_data = SchemaElement()
        xsd_data.tag = "test"

        template_list = None

        try:
            for template_list in self.type_generator.generate_types_excluding(['dict', 'none']):
                with self.assertRaises(Exception):
                    AbstractListRenderer(xsd_data, template_list)
        except AssertionError as error:
            template_list_type = str(type(template_list))
            error.message += ' (template_list type: ' + template_list_type + ')'
            raise AssertionError(error.message)
Ejemplo n.º 14
0
class RendererRenderButtonsTestSuite(TestCase):
    """ render_buttons test suite
    """
    def setUp(self):
        buttons_data = join('utils', 'XSDParser', 'tests', 'data', 'parser',
                            'utils', 'buttons')
        self.buttons_data_handler = DataHandler(buttons_data)

        self.types_generator = VariableTypesGenerator()
        self.default_tag_id = 'string'

        self.renderer = HtmlRenderer()

    def _expected_form(self, is_add_present, is_del_present):
        add_tpl_name = "add_shown" if is_add_present else "add_hidden"
        del_tpl_name = "remove_shown" if is_del_present else "remove_hidden"

        add_html = self.buttons_data_handler.get_html(add_tpl_name)
        del_html = self.buttons_data_handler.get_html(del_tpl_name)

        span = etree.Element('span')
        span.append(add_html)
        span.append(del_html)

        return span

    def test_add_del_false(self):
        is_add_present = False
        is_del_present = False

        form = self.renderer._render_buttons(is_add_present, is_del_present)
        self.assertEqual(form, "")

    def test_add_true_del_false(self):
        is_add_present = True
        is_del_present = False

        # form_string = self.renderer._render_buttons(is_add_present, is_del_present, self.default_tag_id)
        form_string = self.renderer._render_buttons(is_add_present,
                                                    is_del_present)
        form = etree.fromstring('<span>' + form_string + '</span>')

        expected_form = self._expected_form(is_add_present, is_del_present)
        # expected_form_wrapped = '<span>' + self.addButtonPresent + self.delButtonHidden + '</span>'

        self.assertTrue(
            are_equals(form, expected_form)
            # self._xmlStringAreEquals(form_wrapped, expected_form_wrapped)
        )

    def test_add_del_true(self):
        is_add_present = True
        is_del_present = True

        # form_string = render_buttons(is_add_present, is_del_present, self.default_tag_id)
        form_string = self.renderer._render_buttons(is_add_present,
                                                    is_del_present)
        # form_wrapped = '<span>' + form + '</span>'
        form = etree.fromstring('<span>' + form_string + '</span>')

        expected_form = self._expected_form(is_add_present, is_del_present)
        # expected_form_wrapped = '<span>' + self.addButtonPresent + self.delButtonPresent + '</span>'

        self.assertTrue(are_equals(form, expected_form))

    def test_add_false_del_true(self):
        is_add_present = False
        is_del_present = True

        # form_string = render_buttons(is_add_present, is_del_present, self.default_tag_id)
        form_string = self.renderer._render_buttons(is_add_present,
                                                    is_del_present)
        # form_wrapped = '<span>' + form + '</span>'
        form = etree.fromstring('<span>' + form_string + '</span>')

        expected_form = self._expected_form(is_add_present, is_del_present)
        # expected_form_wrapped = '<span>' + self.addButtonHidden + self.delButtonPresent + '</span>'

        self.assertTrue(
            are_equals(form, expected_form)
            # self._xmlStringAreEquals(form_wrapped, expected_form_wrapped)
        )

    def test_add_button_not_bool(self):
        is_add_present = True
        try:
            for is_add_present in self.types_generator.generate_types_excluding(
                ['bool']):
                with self.assertRaises(Exception):
                    # render_buttons(is_add_present, True, self.default_tag_id)
                    self.renderer._render_buttons(is_add_present, True)
        except AssertionError as error:
            is_add_present_type = str(type(is_add_present))
            error.message += ' (is_add_present type: ' + is_add_present_type + ')'
            raise AssertionError(error.message)

    def test_del_button_not_bool(self):
        is_del_present = True
        try:
            for is_del_present in self.types_generator.generate_types_excluding(
                ['bool']):
                with self.assertRaises(Exception):
                    # render_buttons(True, is_del_present, self.default_tag_id)
                    self.renderer._render_buttons(True, is_del_present)
        except AssertionError as error:
            is_del_present_type = str(type(is_del_present))
            error.message += ' (is_del_present type: ' + is_del_present_type + ')'
            raise AssertionError(error.message)

    def test_tag_id_not_str(self):
        for tag_id in self.types_generator.generate_types_excluding(['str']):
            for is_add_present in [True, False]:
                for is_del_present in [True, False]:
                    try:
                        # render_buttons(is_add_present, is_del_present, tag_id)
                        self.renderer._render_buttons(is_add_present,
                                                      is_del_present)
                    except Exception as exc:
                        tag_id_type = str(type(tag_id))
                        self.fail(
                            'Unexpected exception raised with tag_id of type '
                            + tag_id_type + ':' + exc.message)
Ejemplo n.º 15
0
 def setUp(self):
     self.maxDiff = None
     self.type_generator = VariableTypesGenerator()
Ejemplo n.º 16
0
class InitTestSuite(TestCase):
    """ Test suite for initialization of the HtmlRenderer
    """
    def setUp(self):
        self.maxDiff = None
        self.type_generator = VariableTypesGenerator()

    def test_template_list_not_set(self):
        renderer = HtmlRenderer()

        expected_template_keys = [
            'form_error',
            'warning',
            'input',
            'select',
            'btn_add',
            'btn_del',
            'btn_collapse',
        ]

        self.assertEqual(len(renderer.templates), len(expected_template_keys))
        for key in renderer.templates.keys():
            self.assertIn(key, expected_template_keys)

        # self.assertEqual(template_keys, expected_template_keys)
        # TODO test template values to make sure that no template has been modified

    def test_template_list_is_correct_dict(self):
        template_list = {
            "t1": Template('a'),
            "t2": Template('b'),
            "t3": Template('c')
        }

        base_renderer = HtmlRenderer()
        base_renderer.templates.update(template_list)

        base_keys = base_renderer.templates.keys()
        base_keys.sort()

        renderer = HtmlRenderer(template_list)

        renderer_keys = renderer.templates.keys()
        renderer_keys.sort()

        self.assertEqual(renderer_keys, base_keys)

        for key in base_keys:
            self.assertEqual(base_renderer._load_template(key),
                             renderer._load_template(key))

    def test_template_list_is_incorrect_dict(self):
        template = None

        try:
            for template in self.type_generator.generate_types_excluding([]):
                template_list = {"wrong": template}

                with self.assertRaises(Exception):
                    renderer = HtmlRenderer(template_list)
                    renderer._load_template("wrong")
        except AssertionError as error:
            template_type = str(type(template))
            error.message += ' (template type: ' + template_type + ')'
            raise AssertionError(error.message)

    def test_template_list_not_dict(self):
        template_list = None

        try:
            for template_list in self.type_generator.generate_types_excluding(
                ['dict', 'none']):
                with self.assertRaises(Exception):
                    HtmlRenderer(template_list)
        except AssertionError as error:
            template_list_type = str(type(template_list))
            error.message += ' (template_list type: ' + template_list_type + ')'
            raise AssertionError(error.message)
    def setUp(self):
        ul_data = join('utils', 'XSDParser', 'tests', 'data', 'renderer', 'default', 'ul')
        self.ul_data_handler = DataHandler(ul_data)

        self.types_generator = VariableTypesGenerator()
        self.content = '<li>lorem ipsum</li>'
Ejemplo n.º 18
0
 def setUp(self):
     form_error_data = join('curate', 'tests', 'data', 'renderer', 'default')
     self.form_error_data_handler = DataHandler(form_error_data)
     self.types_generator = VariableTypesGenerator()
     self.renderer = HtmlRenderer()
class RendererRenderButtonsTestSuite(TestCase):
    """ render_buttons test suite
    """

    def setUp(self):
        buttons_data = join('curate', 'tests', 'data', 'parser', 'utils', 'buttons')
        self.buttons_data_handler = DataHandler(buttons_data)

        self.types_generator = VariableTypesGenerator()
        self.default_tag_id = 'string'

        self.renderer = HtmlRenderer()

    def _expected_form(self, is_add_present, is_del_present):
        add_tpl_name = "add_shown" if is_add_present else "add_hidden"
        del_tpl_name = "remove_shown" if is_del_present else "remove_hidden"

        add_html = self.buttons_data_handler.get_html(add_tpl_name)
        del_html = self.buttons_data_handler.get_html(del_tpl_name)

        span = etree.Element('span')
        span.append(add_html)
        span.append(del_html)

        return span

    def test_add_del_false(self):
        is_add_present = False
        is_del_present = False

        form = self.renderer._render_buttons(is_add_present, is_del_present)
        self.assertEqual(form, "")

    def test_add_true_del_false(self):
        is_add_present = True
        is_del_present = False

        # form_string = self.renderer._render_buttons(is_add_present, is_del_present, self.default_tag_id)
        form_string = self.renderer._render_buttons(is_add_present, is_del_present)
        form = etree.fromstring('<span>' + form_string + '</span>')

        expected_form = self._expected_form(is_add_present, is_del_present)
        # expected_form_wrapped = '<span>' + self.addButtonPresent + self.delButtonHidden + '</span>'

        self.assertTrue(
            are_equals(form, expected_form)
            # self._xmlStringAreEquals(form_wrapped, expected_form_wrapped)
        )

    def test_add_del_true(self):
        is_add_present = True
        is_del_present = True

        # form_string = render_buttons(is_add_present, is_del_present, self.default_tag_id)
        form_string = self.renderer._render_buttons(is_add_present, is_del_present)
        # form_wrapped = '<span>' + form + '</span>'
        form = etree.fromstring('<span>' + form_string + '</span>')

        expected_form = self._expected_form(is_add_present, is_del_present)
        # expected_form_wrapped = '<span>' + self.addButtonPresent + self.delButtonPresent + '</span>'

        self.assertTrue(
            are_equals(form, expected_form)
        )

    def test_add_false_del_true(self):
        is_add_present = False
        is_del_present = True

        # form_string = render_buttons(is_add_present, is_del_present, self.default_tag_id)
        form_string = self.renderer._render_buttons(is_add_present, is_del_present)
        # form_wrapped = '<span>' + form + '</span>'
        form = etree.fromstring('<span>' + form_string + '</span>')

        expected_form = self._expected_form(is_add_present, is_del_present)
        # expected_form_wrapped = '<span>' + self.addButtonHidden + self.delButtonPresent + '</span>'

        self.assertTrue(
            are_equals(form, expected_form)
            # self._xmlStringAreEquals(form_wrapped, expected_form_wrapped)
        )

    def test_add_button_not_bool(self):
        is_add_present = True
        try:
            for is_add_present in self.types_generator.generate_types_excluding(['bool']):
                with self.assertRaises(Exception):
                    # render_buttons(is_add_present, True, self.default_tag_id)
                    self.renderer._render_buttons(is_add_present, True)
        except AssertionError as error:
            is_add_present_type = str(type(is_add_present))
            error.message += ' (is_add_present type: ' + is_add_present_type + ')'
            raise AssertionError(error.message)

    def test_del_button_not_bool(self):
        is_del_present = True
        try:
            for is_del_present in self.types_generator.generate_types_excluding(['bool']):
                with self.assertRaises(Exception):
                    # render_buttons(True, is_del_present, self.default_tag_id)
                    self.renderer._render_buttons(True, is_del_present)
        except AssertionError as error:
            is_del_present_type = str(type(is_del_present))
            error.message += ' (is_del_present type: ' + is_del_present_type + ')'
            raise AssertionError(error.message)

    def test_tag_id_not_str(self):
        for tag_id in self.types_generator.generate_types_excluding(['str']):
            for is_add_present in [True, False]:
                for is_del_present in [True, False]:
                    try:
                        # render_buttons(is_add_present, is_del_present, tag_id)
                        self.renderer._render_buttons(is_add_present, is_del_present)
                    except Exception as exc:
                        tag_id_type = str(type(tag_id))
                        self.fail('Unexpected exception raised with tag_id of type ' + tag_id_type + ':' + exc.message)
Ejemplo n.º 20
0
 def setUp(self):
     self.renderer = BaseRenderer()
     self.type_generator = VariableTypesGenerator()
class InitTestSuite(TestCase):

    def setUp(self):
        self.maxDiff = None
        self.type_generator = VariableTypesGenerator()

    def test_template_list_not_set(self):
        renderer = BaseRenderer()

        # Loose comparison is enough for this test
        self.assertEqual(len(renderer.templates), 0)

    def test_template_list_is_correct_dict(self):

        template_list = {
            "t1": Template('a'),
            "t2": Template('b'),
            "t3": Template('c')
        }

        base_renderer = BaseRenderer()
        base_renderer.templates.update(template_list)

        renderer = BaseRenderer(template_list)

        self.assertEqual(renderer.templates.keys(), base_renderer.templates.keys())

        for tpl_key in renderer.templates.keys():
            try:
                renderer._load_template(tpl_key)
            except Exception as exc:
                self.fail(exc.message)

    def test_template_list_is_incorrect_dict(self):
        template = None

        try:
            for template in self.type_generator.generate_types_excluding([]):
                template_list = {
                    "wrong": template
                }

                with self.assertRaises(Exception):
                    renderer = BaseRenderer(template_list)
                    renderer._load_template("wrong")
        except AssertionError as error:
            template_type = str(type(template))
            error.message += ' (template type: ' + template_type + ')'
            raise AssertionError(error.message)

    def test_template_list_not_dict(self):
        template_list = None

        try:
            for template_list in self.type_generator.generate_types_excluding(['dict', 'none']):
                with self.assertRaises(Exception):
                    BaseRenderer(template_list)
        except AssertionError as error:
            template_list_type = str(type(template_list))
            error.message += ' (template_list type: ' + template_list_type + ')'
            raise AssertionError(error.message)
 def setUp(self):
     self.renderer = BaseRenderer()
     self.type_generator = VariableTypesGenerator()
class InitTestSuite(TestCase):
    """ Test suite for initialization of the HtmlRenderer
    """

    def setUp(self):
        self.maxDiff = None
        self.type_generator = VariableTypesGenerator()

    def test_template_list_not_set(self):
        renderer = HtmlRenderer()

        expected_template_keys = [
            'form_error',
            'warning',
            'input',
            'select',
            'btn_add',
            'btn_del',
            'btn_collapse',
        ]

        self.assertEqual(len(renderer.templates), len(expected_template_keys))
        for key in renderer.templates.keys():
            self.assertIn(key, expected_template_keys)

        # self.assertEqual(template_keys, expected_template_keys)
        # TODO test template values to make sure that no template has been modified

    def test_template_list_is_correct_dict(self):
        template_list = {
            "t1": Template('a'),
            "t2": Template('b'),
            "t3": Template('c')
        }

        base_renderer = HtmlRenderer()
        base_renderer.templates.update(template_list)

        base_keys = base_renderer.templates.keys()
        base_keys.sort()

        renderer = HtmlRenderer(template_list)

        renderer_keys = renderer.templates.keys()
        renderer_keys.sort()

        self.assertEqual(renderer_keys, base_keys)

        for key in base_keys:
            self.assertEqual(
                base_renderer._load_template(key),
                renderer._load_template(key)
            )

    def test_template_list_is_incorrect_dict(self):
        template = None

        try:
            for template in self.type_generator.generate_types_excluding([]):
                template_list = {
                    "wrong": template
                }

                with self.assertRaises(Exception):
                    renderer = HtmlRenderer(template_list)
                    renderer._load_template("wrong")
        except AssertionError as error:
            template_type = str(type(template))
            error.message += ' (template type: ' + template_type + ')'
            raise AssertionError(error.message)

    def test_template_list_not_dict(self):
        template_list = None

        try:
            for template_list in self.type_generator.generate_types_excluding(['dict', 'none']):
                with self.assertRaises(Exception):
                    HtmlRenderer(template_list)
        except AssertionError as error:
            template_list_type = str(type(template_list))
            error.message += ' (template_list type: ' + template_list_type + ')'
            raise AssertionError(error.message)
class AbstractRenderUlTestSuite(TestCase):

    def setUp(self):
        ul_data = join('utils', 'XSDParser', 'tests', 'data', 'renderer', 'default', 'ul')
        self.ul_data_handler = DataHandler(ul_data)

        self.types_generator = VariableTypesGenerator()
        self.content = '<li>lorem ipsum</li>'

    def test_elem_id_str_chosen_true(self):
        element_id = 'string'
        chosen = True

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(result_string, render_ul(unicode(self.content), unicode(element_id), chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_str_ch_true')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_elem_id_str_chosen_false(self):
        element_id = 'string'
        chosen = False

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(result_string, render_ul(unicode(self.content), unicode(element_id), chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_str_ch_false')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_elem_id_empty_str_chosen_true(self):
        element_id = ''
        chosen = True

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(result_string, render_ul(unicode(self.content), unicode(element_id), chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_empty_ch_true')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_elem_id_empty_str_chosen_false(self):
        element_id = ''
        chosen = False

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(result_string, render_ul(unicode(self.content), unicode(element_id), chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_empty_ch_false')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_elem_id_none_chosen_true(self):
        element_id = None
        chosen = True

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(result_string, render_ul(unicode(self.content), element_id, chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_none_ch_true')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_elem_id_none_chosen_false(self):
        element_id = 'string'
        chosen = True

        result_string = render_ul(self.content, element_id, chosen)
        self.assertEqual(result_string, render_ul(unicode(self.content), element_id, chosen))
        # print result_string

        result_html = etree.fromstring(result_string)
        expected_html = self.ul_data_handler.get_html2('elem_str_ch_true')

        self.assertTrue(are_equals(result_html, expected_html))

    def test_content_not_str(self):
        content = 'string'
        element_id = 'string'
        chosen = True

        try:
            for content in self.types_generator.generate_types_excluding(['str', 'unicode']):
                with self.assertRaises(Exception):
                    render_ul(content, element_id, chosen)
        except AssertionError as error:
            content_type = str(type(content))
            error.message += ' (content type: ' + content_type + ')'
            raise AssertionError(error.message)

    def test_elem_id_not_str_not_none(self):
        content = 'string'
        element_id = 'string'
        chosen = True

        try:
            for element_id in self.types_generator.generate_types_excluding(['str', 'unicode', 'none']):
                with self.assertRaises(Exception):
                    render_ul(content, element_id, chosen)
        except AssertionError as error:
            element_id_type = str(type(element_id))
            error.message += ' (element_id type: ' + element_id_type + ')'
            raise AssertionError(error.message)

    def test_chosen_not_bool(self):
        content = 'string'
        element_id = 'string'
        chosen = True

        try:
            for chosen in self.types_generator.generate_types_excluding(['bool']):
                with self.assertRaises(Exception):
                    render_ul(content, element_id, chosen)
        except AssertionError as error:
            chosen_type = str(type(chosen))
            error.message += ' (content type: ' + chosen_type + ')'
            raise AssertionError(error.message)