def test_conditionally_shown_top_level_form_elements_do_not_render_when_hidden( self): builder = Builder(self.builder_json) hide_secret_form = Form(self.hide_secret_form_json, builder) hide_secret_form.render_components() self.assertEqual( '<p>wrong</p>', hide_secret_form.input_components['username'].html_component) self.assertEqual( '<p>incorrect</p>', hide_secret_form.input_components['password'].html_component) self.assertEqual( '', hide_secret_form.input_components['secret'].html_component) show_secret_form = Form(self.show_secret_form_json, builder) show_secret_form.render_components() self.assertEqual( '<p>user</p>', show_secret_form.input_components['username'].html_component) self.assertEqual( '<p>secret</p>', show_secret_form.input_components['password'].html_component) self.assertEqual( '<p>Secret message</p>', show_secret_form.input_components['secret'].html_component)
def test_conditionally_shown_form_elements_do_not_render_when_hidden(self): builder = Builder(self.builder_json) hide_password_form = Form(self.hide_password_form_json, builder) hide_password_form.render_components() self.assertEqual( '<p>hide!</p>', hide_password_form.input_components['textField'].html_component) self.assertEqual( '', hide_password_form.input_components['maybeTextField']. html_component) self.assertEqual( '', hide_password_form.input_components['maybePassword']. html_component) show_textfield_form = Form(self.show_textfield_form_json, builder) show_textfield_form.render_components() self.assertEqual( '<p>show!</p>', show_textfield_form.input_components['textField'].html_component) self.assertEqual( '<p>maybe yes</p>', show_textfield_form. input_components['maybeTextField'].html_component) self.assertEqual( '<p>hunter2</p>', show_textfield_form. input_components['maybePassword'].html_component)
class viewRenderEmailComponent(ComponentTestCase): def test_view_render(self): self.form_check_default = Form(self.form_json_check_default, self.builder) self.form_check_default.render_components() # EmailComponent email = self.form_check_default.input_components['email'] self.assertEqual(email.html_component, '<p>[email protected]</p>')
def test_conditionally_shown_form_elements_for_global_data_condition_in_data_grid_do_not_render_when_hidden( self): builder = Builder(self.builder_json) show_global_secret_only_form = Form( self.show_global_secret_only_form_json, builder) show_global_secret_only_form.render_components() show_global_secret_only_datagrid = show_global_secret_only_form.input_components[ 'dataGrid'] show_global_secret_only_first_row = show_global_secret_only_datagrid.rows[ 0] self.assertEqual( '<tr><td><table><tr><td><p>wrong</p></td><td><p>incorrect</p></td><td></td><td><p>Another secret message</p></td></tr></table></td></tr>', show_global_secret_only_first_row.html_component) self.assertEqual( '<p>wrong</p>', show_global_secret_only_first_row. input_components['username3'].html_component) self.assertEqual( '<p>incorrect</p>', show_global_secret_only_first_row. input_components['password3'].html_component) self.assertEqual( '', show_global_secret_only_first_row.input_components['secret3']. html_component) self.assertEqual( '<p>Another secret message</p>', show_global_secret_only_first_row. input_components['globalSecret'].html_component) show_global_secret_only_second_row = show_global_secret_only_datagrid.rows[ 1] self.assertEqual( '<tr><td><table><tr><td><p>wrong</p></td><td><p>incorrect</p></td><td></td><td><p>Another secret message</p></td></tr></table></td></tr>', show_global_secret_only_second_row.html_component) self.assertEqual( '<p>wrong</p>', show_global_secret_only_second_row. input_components['username3'].html_component) self.assertEqual( '<p>incorrect</p>', show_global_secret_only_second_row. input_components['password3'].html_component) self.assertEqual( '', show_global_secret_only_second_row.input_components['secret3']. html_component) self.assertEqual( '<p>Another secret message</p>', show_global_secret_only_second_row. input_components['globalSecret'].html_component) # Tying it all together self.assertEqual( f'<table>{show_global_secret_only_first_row.html_component}{show_global_secret_only_second_row.html_component}</table>', show_global_secret_only_datagrid.html_component) hide_global_secret_only_form = Form( self.hide_global_secret_only_form_json, builder) hide_global_secret_only_form.render_components() hide_global_secret_only_datagrid = hide_global_secret_only_form.input_components[ 'dataGrid'] hide_global_secret_only_first_row = hide_global_secret_only_datagrid.rows[ 0] self.assertEqual( '<tr><td><table><tr><td><p>user</p></td><td><p>secret</p></td><td><p>Secret message</p></td><td></td></tr></table></td></tr>', hide_global_secret_only_first_row.html_component) self.assertEqual( '<p>user</p>', hide_global_secret_only_first_row. input_components['username3'].html_component) self.assertEqual( '<p>secret</p>', hide_global_secret_only_first_row. input_components['password3'].html_component) self.assertEqual( '<p>Secret message</p>', hide_global_secret_only_first_row. input_components['secret3'].html_component) self.assertEqual( '', hide_global_secret_only_first_row. input_components['globalSecret'].html_component) hide_global_secret_only_second_row = hide_global_secret_only_datagrid.rows[ 0] self.assertEqual( '<tr><td><table><tr><td><p>user</p></td><td><p>secret</p></td><td><p>Secret message</p></td><td></td></tr></table></td></tr>', hide_global_secret_only_second_row.html_component) self.assertEqual( '<p>user</p>', hide_global_secret_only_second_row. input_components['username3'].html_component) self.assertEqual( '<p>secret</p>', hide_global_secret_only_second_row. input_components['password3'].html_component) self.assertEqual( '<p>Secret message</p>', hide_global_secret_only_second_row. input_components['secret3'].html_component) self.assertEqual( '', hide_global_secret_only_second_row. input_components['globalSecret'].html_component) # Tying it all together self.assertEqual( f'<table>{hide_global_secret_only_first_row.html_component}{hide_global_secret_only_second_row.html_component}</table>', hide_global_secret_only_datagrid.html_component)