本文整理汇总了Python中mgi.tests.DataHandler.get_html方法的典型用法代码示例。如果您正苦于以下问题:Python DataHandler.get_html方法的具体用法?Python DataHandler.get_html怎么用?Python DataHandler.get_html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mgi.tests.DataHandler
的用法示例。
在下文中一共展示了DataHandler.get_html方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ChoiceCreateSchemaTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_html [as 别名]
class ChoiceCreateSchemaTestSuite(SimpleTestCase):
"""
"""
def setUp(self):
xsd_files_path = join(XSD_FILES_PATH, 'choice')
self.xsd_handler = DataHandler(xsd_files_path)
html_files_path = join(HTML_FILES_PATH, 'choice')
self.html_handler = DataHandler(html_files_path)
engine = import_module('django.contrib.sessions.backends.db')
session = engine.SessionStore()
session.save()
self.client.cookies['sessionid'] = session.session_key
session['curate_edit'] = False
form_data = FormData()
form_data.name = ''
form_data.user = ''
form_data.template = ''
form_data.save()
session['curateFormData'] = str(form_data.pk)
session['nb_html_tags'] = 0
session['implicit_extension'] = True
session['mapTagID'] = {}
session['nbChoicesID'] = 0
session.save()
# def test_any_basic(self):
# pass
#
# def test_any_unbounded(self):
# pass
def test_choice_basic(self):
file_path = join('choice', 'basic')
xsd_data = self.xsd_handler.get_xsd(file_path)
session = self.client.session
session['xmlDocTree'] = etree.tostring(xsd_data)
session.save()
result = retrieve_rendered_form(self.client)
expected_result = self.html_handler.get_html(file_path)
self.assertTrue(are_equals(result[1], expected_result))
示例2: RendererRenderCollapseButtonTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_html [as 别名]
class RendererRenderCollapseButtonTestSuite(TestCase):
"""
"""
def setUp(self):
collapse_data = join('curate', 'tests', 'data', 'renderer', 'default')
self.collapse_data_handler = DataHandler(collapse_data)
self.renderer = HtmlRenderer()
def test_button(self):
result_string = self.renderer._render_collapse_button()
result_html = etree.fromstring(result_string)
expected_html = self.collapse_data_handler.get_html('collapse')
self.assertTrue(are_equals(result_html, expected_html))
示例3: RenderFormErrorTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_html [as 别名]
class RenderFormErrorTestSuite(TestCase):
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()
def test_message_str(self):
form_error_message = 'Sample error message'
result_string = self.renderer._render_form_error(form_error_message)
self.assertEqual(result_string, self.renderer._render_form_error(unicode(form_error_message)))
result_html = etree.fromstring(result_string)
expected_html = self.form_error_data_handler.get_html('form_error')
self.assertTrue(are_equals(result_html, expected_html))
示例4: RendererRenderSelectTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_html [as 别名]
class RendererRenderSelectTestSuite(TestCase):
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()
def test_id_str_options_list(self):
options = [
('opt1', 'opt1', False),
('opt2', 'opt2', False),
('opt3', 'opt3', True)
]
result_string = self.renderer._render_select(self.select_id, self.select_class, options)
self.assertEqual(
result_string,
self.renderer._render_select(unicode(self.select_id), self.select_class, options)
)
result_html = etree.fromstring(result_string)
expected_html = self.select_data_handler.get_html('id_str_options_list')
self.assertTrue(are_equals(result_html, expected_html))
def test_id_str_options_empty_list(self):
options = []
result_string = self.renderer._render_select(self.select_id, self.select_class, options)
self.assertEqual(
result_string,
self.renderer._render_select(unicode(self.select_id), self.select_class, options)
)
result_html = etree.fromstring(result_string)
expected_html = self.select_data_handler.get_html('id_str_options_empty')
self.assertTrue(are_equals(result_html, expected_html))
def test_id_none_options_list(self):
options = [
('opt1', 'opt1', False),
('opt2', 'opt2', False),
('opt3', 'opt3', True)
]
result_string = self.renderer._render_select(None, self.select_class, options)
self.assertEqual(result_string, self.renderer._render_select(None, self.select_class, options))
# print result_string
result_html = etree.fromstring(result_string)
expected_html = self.select_data_handler.get_html('id_none_options_list')
self.assertTrue(are_equals(result_html, expected_html))
def test_id_none_options_empty_list(self):
options = []
result_string = self.renderer._render_select(None, self.select_class, options)
self.assertEqual(result_string, self.renderer._render_select(None, self.select_class, options))
# print result_string
result_html = etree.fromstring(result_string)
expected_html = self.select_data_handler.get_html('id_none_options_empty')
self.assertTrue(are_equals(result_html, expected_html))
# def test_id_not_str_not_none(self):
# element_id = 'string'
#
# try:
# for element_id in self.types_generator.generate_types_excluding(['str', 'unicode', 'none']):
# with self.assertRaises(Exception):
# self.renderer._render_select(element_id, self.select_class, [])
# 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_options_not_list(self):
# options = []
#
# try:
# for options in self.types_generator.generate_types_excluding(['list']):
# with self.assertRaises(Exception):
# self.renderer._render_select(self.select_id, self.select_class, options)
# except AssertionError as error:
# options_type = str(type(options))
# error.message += ' (options type: ' + options_type + ')'
# raise AssertionError(error.message)
# def test_options_not_list_of_tuple(self):
# options = [()]
#
# try:
#.........这里部分代码省略.........
示例5: RenderInputTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_html [as 别名]
class RenderInputTestSuite(TestCase):
def setUp(self):
input_data = join('utils', 'XSDParser', 'tests', 'data', 'renderer', 'html', 'input')
self.input_data_handler = DataHandler(input_data)
self.types_generator = VariableTypesGenerator()
self.renderer = HtmlRenderer()
def test_input_placeholder_str(self):
input_element = create_mock_db_input(
placeholder='string'
)
result_string = self.renderer._render_input(input_element)
result_html = etree.fromstring(result_string)
expected_html = self.input_data_handler.get_html('placeholder')
self.assertTrue(are_equals(result_html, expected_html))
# def test_input_placeholder_not_str(self):
# placeholder = None
#
# try:
# for placeholder in self.types_generator.generate_types_excluding(['str', 'unicode']):
# input_element = create_mock_db_input(
# placeholder=placeholder
# )
#
# with self.assertRaises(Exception):
# self.renderer._render_input(input_element)
# except AssertionError as error:
# placeholder_type = str(type(placeholder))
# error.message += ' (title type: ' + placeholder_type + ')'
# raise AssertionError(error.message)
def test_input_title_str(self):
input_element = create_mock_db_input(
title='string'
)
result_string = self.renderer._render_input(input_element)
result_html = etree.fromstring(result_string)
expected_html = self.input_data_handler.get_html('title')
self.assertTrue(are_equals(result_html, expected_html))
# def test_input_title_not_str(self):
# title = None
#
# try:
# for title in self.types_generator.generate_types_excluding(['str', 'unicode']):
# with self.assertRaises(Exception):
# input_element = create_mock_db_input(
# title=title
# )
#
# self.renderer._render_input(input_element)
# except AssertionError as error:
# title_type = str(type(title))
# error.message += ' (title type: ' + title_type + ')'
# raise AssertionError(error.message)
def test_input_value_str(self):
input_element = create_mock_db_input(
value="string"
)
result_string = self.renderer._render_input(input_element)
result_html = etree.fromstring(result_string)
expected_html = self.input_data_handler.get_html('input_str')
self.assertTrue(are_equals(result_html, expected_html))
def test_input_value_none(self):
input_element = create_mock_db_input(
value=None
)
result_string = self.renderer._render_input(input_element)
result_html = etree.fromstring(result_string)
expected_html = self.input_data_handler.get_html('input_none')
self.assertTrue(are_equals(result_html, expected_html))
def test_input_not_schema_element(self):
input_element = SchemaElement()
try:
for input_element in self.types_generator.possible_types:
with self.assertRaises(TypeError):
self.renderer._render_input(input_element)
except AssertionError as error:
input_type = str(type(input_element))
error.message += ' (input type: ' + input_type + ')'
raise AssertionError(error.message)
示例6: RendererRenderButtonsTestSuite
# 需要导入模块: from mgi.tests import DataHandler [as 别名]
# 或者: from mgi.tests.DataHandler import get_html [as 别名]
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)
#.........这里部分代码省略.........