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))
class RendererRenderCollapseButtonTestSuite(TestCase): """ """ def setUp(self): collapse_data = join('utils', 'XSDParser', '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))
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))
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))
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: # for item in self.types_generator.generate_types_excluding(['tuple']): # options[0] = item # # with self.assertRaises(Exception): # self.renderer._render_select(self.select_id, self.select_class, options) # except AssertionError as error: # item_type = str(type(options[0])) # error.message += ' (item type: ' + item_type + ')' # raise AssertionError(error.message) # def test_options_malformed_list(self): # options = [()] # # try: # for param in self.types_generator.generate_types_excluding(['str', 'unicode']): # options[0] = (param, '', False) # with self.assertRaises(Exception): # self.renderer._render_select(self.select_id, self.select_class, options) # # options[0] = ('', param, False) # with self.assertRaises(Exception): # self.renderer._render_select(self.select_id, self.select_class, options) # # for param in self.types_generator.generate_types_excluding(['bool']): # options[0] = ('', '', param) # with self.assertRaises(Exception): # self.renderer._render_select(self.select_id, self.select_class, options) # # with self.assertRaises(Exception): # self.renderer._render_select(self.select_id, self.select_class, [('elem0', 'elem1')]) # except AssertionError as error: # error.message += ' (option not considered as malformed: ' + str(options) + ')' # raise AssertionError(error.message) # FIXME New version (merge with up) def test_select_id_is_db_elem(self): pass def test_select_id_not_db_element(self): pass def test_select_id_not_str(self): pass def test_select_class_is_str(self): pass def test_select_class_is_not_str(self): pass def test_options_list_is_list_with_good_tuples(self): pass def test_options_list_is_list_with_bad_tuples(self): pass def test_options_list_is_list_without_tuples(self): pass def test_options_list_is_not_list(self): pass
class RenderInputTestSuite(TestCase): 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 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') expected_html = self.input_data_handler.get_html( 'val_empty_pl_str_tt_empty') 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( 'val_empty_pl_empty_tt_str') 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( 'val_str_pl_empty_tt_empty') 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( 'val_empty_pl_empty_tt_empty') 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)
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)
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: # for item in self.types_generator.generate_types_excluding(['tuple']): # options[0] = item # # with self.assertRaises(Exception): # self.renderer._render_select(self.select_id, self.select_class, options) # except AssertionError as error: # item_type = str(type(options[0])) # error.message += ' (item type: ' + item_type + ')' # raise AssertionError(error.message) # def test_options_malformed_list(self): # options = [()] # # try: # for param in self.types_generator.generate_types_excluding(['str', 'unicode']): # options[0] = (param, '', False) # with self.assertRaises(Exception): # self.renderer._render_select(self.select_id, self.select_class, options) # # options[0] = ('', param, False) # with self.assertRaises(Exception): # self.renderer._render_select(self.select_id, self.select_class, options) # # for param in self.types_generator.generate_types_excluding(['bool']): # options[0] = ('', '', param) # with self.assertRaises(Exception): # self.renderer._render_select(self.select_id, self.select_class, options) # # with self.assertRaises(Exception): # self.renderer._render_select(self.select_id, self.select_class, [('elem0', 'elem1')]) # except AssertionError as error: # error.message += ' (option not considered as malformed: ' + str(options) + ')' # raise AssertionError(error.message) # FIXME New version (merge with up) def test_select_id_is_db_elem(self): pass def test_select_id_not_db_element(self): pass def test_select_id_not_str(self): pass def test_select_class_is_str(self): pass def test_select_class_is_not_str(self): pass def test_options_list_is_list_with_good_tuples(self): pass def test_options_list_is_list_with_bad_tuples(self): pass def test_options_list_is_list_without_tuples(self): pass def test_options_list_is_not_list(self): pass
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)
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)