def test_error_on_nested_forms_for_nonform(self): form_outer = HtmlForm('outer_form') div = form_outer.div() form_inner = div.form('inner_form') div_sub = form_inner.div() with pytest.raises(Exception): div_sub.get_form()
def test_set_codes_constructor_with_list(self, content_as_dicts): html_form = HtmlForm(id_html='form_id') rl: ResultChoice = html_form.result_choice(content=content_as_dicts, listing_index='column_1', row_selected=None) rl.set_codes("column_1", [1, 2]) rl.compose()
def test_resultEditor(self, content_as_dicts): form = HtmlForm(id_html='form_id') re = ResultEditor(content=content_as_dicts, listing_index='column_id', row_selected='2') form.add(re) re.compose()
def test_indirect_format_id(self, content_as_dicts): html_form = HtmlForm(id_html='form_id') html_div = html_form.div() rc = html_div.result_choice(content=content_as_dicts, listing_index='column_1', row_selected=None) assert rc.get_form().id_html == "form_id"
def test_setter_listing_index(self, content_as_dicts): html_form = HtmlForm(id_html='form_id') rl = html_form.result_choice(content=content_as_dicts, listing_index='column_1', row_selected=None) assert rl.listing_index == [ 'column_1', ]
def test_constructor(self, content_as_dicts): # just test if it creates an object html_form = HtmlForm(id_html='form_id') rl = html_form.result_choice(content=content_as_dicts, listing_index='column_1', row_selected=None) rl.compose() assert len(rl.table) == len(content_as_dicts) + 1 # +1 for header
def test_set_codes_constructor_with_dict_and_missing_list_index( self, content_as_dicts): html_form = HtmlForm(id_html='form_id') rl: ResultChoice = html_form.result_choice(content=content_as_dicts, listing_index='not_there', row_selected=None) with pytest.raises(Exception): rl.set_codes("column_1", {1: "a", 2: "c"}) rl.compose()
def test_row_selection_with_multible_columns(self, content_as_dicts): html_form = HtmlForm(id_html='form_id') rl = html_form.result_choice(content=content_as_dicts, listing_index=['column_1', 'column_2'], row_selected={ 'column_1': 4, 'column_2': 5 }) rl.compose() assert 'name="_rct_selected_column_1" value="4"' in str(rl) assert 'name="_rct_selected_column_2" value="5"' in str(rl)
def test__is_selected_row(self, content_as_dicts): html_form = HtmlForm(id_html='form_id') rl: ResultChoice = html_form.result_choice(content=content_as_dicts, listing_index='column_1', row_selected=[{ 'column_1': '4' }, { 'column_1': '10' }]) rl.compose() assert rl._is_selected_row({'column_1': '4'}) assert rl._is_selected_row({'column_1': '10'}) assert not rl._is_selected_row({'column_1': '5'}) assert not rl._is_selected_row({'column_2': '4'}) assert not rl._is_selected_row({'column_2': '5'}) # test with list as input rl: ResultChoice = html_form.result_choice(content=content_as_dicts, listing_index=['column_1'], row_selected=[{ 'column_1': '4' }, { 'column_1': '10' }]) rl.compose() assert rl._is_selected_row({'column_1': '4'}) assert not rl._is_selected_row({'column_1': '5'}) # test with multiple columns rl: ResultChoice = html_form.result_choice( content=content_as_dicts, listing_index=['column_1', 'column_2'], row_selected=[{ 'column_1': '4', 'column_2': '5' }, { 'column_1': '6', 'column_2': '7' }]) rl.compose() assert rl._is_selected_row({'column_1': 4, 'column_2': 5}) assert rl._is_selected_row({'column_1': 6, 'column_2': 7}) assert not rl._is_selected_row({'column_1': 2, 'column_2': 3}) assert not rl._is_selected_row({'column_1': 4, 'column_2': 3}) assert not rl._is_selected_row({'column_1': 1, 'column_2': 7})
def test_select_multiple_rows_at_once(self, content_as_dicts): html_form = HtmlForm(id_html='form_id') rl: ResultChoice = html_form.result_choice(content=content_as_dicts, listing_index='column_1', row_selected=[{ 'column_1': '4' }, { 'column_1': '10' }]) rl.compose() assert 'white' in str(rl) assert 'name="_rct_selected_column_1" value="4;10"' in str(rl)
def test_with_alchemy(self): from sqlalchemy import Table, MetaData, Column, Integer, String, select from sqlalchemy import create_engine con = create_engine('sqlite://').connect() meta = MetaData(bind=con) tab = Table("test_table", meta, Column("column_a", Integer), Column("column_b", String)) meta.create_all() con.execute(tab.insert().values((1, "a"))) result = con.execute(select([tab.c.column_b])).fetchall() html_form = HtmlForm(id_html='form_id') rc: ResultChoice = html_form.result_choice(content=result, listing_index='not_there') assert "column_b" in str(rc)
def test_row_selection(self, content_as_dicts): html_form = HtmlForm(id_html='form_id') rl = html_form.result_choice(content=content_as_dicts, listing_index='column_1', row_selected={'column_1': 4}) rl.compose() assert 'name="_rct_selected_column_1" value="4"' in str(rl) # Do it again with a string input html_form = HtmlForm(id_html='form_id') rl = html_form.result_choice(content=content_as_dicts, listing_index='column_1', row_selected={'column_1': '4'}) rl.compose() assert 'name="_rct_selected_column_1" value="4"' in str(rl)
def test_pass_parent_to_child_by_reference(self): form = HtmlForm(id_html='id_form123') div = form.div() assert id(div.parent) == id(form)
def test_pass_parent_to_child(self): form = HtmlForm(id_html='id_form123') div = form.div() assert div.parent == form
def test_multiple_index(self, content_as_dicts): html_form = HtmlForm(id_html='form_id') rl = html_form.result_choice(content=content_as_dicts, listing_index=['column_1', 'column_2'], row_selected={}) rl.compose()
def test_constructor_empty_content(self): html_form = HtmlForm(id_html='form_id') rl = html_form.result_choice(content=None, listing_index='column_1', row_selected=None) rl.compose()