def test_assets(template_render_tag, template_context, source_listdics): table1 = Table( source=source_listdics, plugins=[Bootstrap4Plugin()] ) table2 = Table( source=source_listdics, plugins=[Bootstrap4Plugin()] ) context = template_context({'table1': table1, 'table2': table2}) rendered_js = template_render_tag('sitetables', 'sitetables_js table1 table2', context=context) assert 'jquery.dataTables' in rendered_js assert 'bootstrap4' in rendered_js assert str(rendered_js).count('script') == 4 rendered_css = template_render_tag('sitetables', 'sitetables_css table1 table2', context=context) assert 'jquery.dataTables' in rendered_css assert 'bootstrap4' in rendered_css assert str(rendered_css).count('link') == 2
def test_tables_registry(source_listdics): table1 = Table(source=source_listdics, name='one') table2 = Table(source=source_listdics) registry = Table.tables_registry assert len(list(registry.keys())) == 2 assert registry['one'] is table1
def test_source_listdicts(source_listdics): table = Table(source=source_listdics) rows = table.get_rows() assert len(rows) == 2 assert rows[0]['one'] == 'a' assert rows[1]['two'] == 'e' assert table.source.row_id == 'one'
def test_rows(render, source_listdics): assert render(Table(source_listdics), tag='sitetable_rows') == '' # Because of no DOM init option. rendered = render(Table( source={ 'source': source_listdics, 'options': {'init_dom': True}, } ), tag='sitetable_rows') assert '<td>a</td>' in rendered
def test_bootstrap4(source_listdics): table = Table( source=source_listdics, plugins=[ Bootstrap4Plugin(), ] ) assert len(table.get_assets_css()) == 2 js = table.get_assets_js() assert len(js) == 2 assert 'bootstrap4.' in js[1]
def test_foundation(source_listdics): table = Table( source=source_listdics, plugins=[ FoundationPlugin(), ] ) assert len(table.get_assets_css()) == 2 js = table.get_assets_js() assert len(js) == 2 assert 'foundation.' in js[1]
def test_semantic(source_listdics): table = Table( source=source_listdics, plugins=[ SemanticPlugin(), ] ) assert len(table.get_assets_css()) == 2 js = table.get_assets_js() assert len(js) == 2 assert 'semanticui.' in js[1]
def test_jqueryui(source_listdics): table = Table( source=source_listdics, plugins=[ JqueryUiPlugin(), ] ) assert len(table.get_assets_css()) == 2 js = table.get_assets_js() assert len(js) == 2 assert 'jqueryui.' in js[1]
def test_config(render, source_listdics): rendered = render(Table(source_listdics), tag='sitetable_config') assert '"columns":' in rendered assert '"data":' in rendered assert '"name": "one"' in rendered assert '"one": "a"' in rendered assert "function" in rendered assert '"function' not in rendered table = Table(source=Article, on_server=True) rendered = render(table, tag='sitetable_config') assert '"url": "/sitetables/responder/"' in rendered
def test_sitetable_tag(template_render_tag, source_listdics): with pytest.raises(TemplateSyntaxError): template_render_tag('sitetables', 'sitetable_config table') Table(source_listdics, name='mytable') template_render_tag('sitetables', 'sitetable_config table', context={'table': 'mytable'})
def test_source_model(setup_articles): source = Article table = Table(source) assert not table.get_rows() # No articles in DB. setup_articles() table = Table(source) rows = list(table.get_rows()) assert len(rows) == 5 assert table.source.row_id == 'id'
def test_i18n(source_listdics, settings): table = Table(source=source_listdics, plugins=[I18nPlugin()]) assert len(table.get_assets_css()) == 1 assert len(table.get_assets_js()) == 1 config = table.get_config() assert 'language' not in config # Unable to autodetect lang activate('ru') # Autodetect. config = table.get_config() assert 'Russian' in config['language']['url'] # Manual. config = Table(source=source_listdics, plugins=[I18nPlugin('de')]).get_config() assert 'German' in config['language']['url'] deactivate_all()
def test_responder(setup_articles, request_client): url = ('sitetables:respond', {}) table1 = Table(source={ 'source': Article, 'options': { 'columns_add': { 'title_custom': 'Added Column', } }, }, on_server=True) client = request_client(ajax=True) response = client.post(url) assert response.status_code == 400 assert response.json() == {'error': 'No data found for "" table'} setup_articles() response = client.post( url, data={ 'tableName': table1.name, 'search[value]': 'my', 'length': 9999999, 'orderBogus': 'some', 'order[0][column]': 0, 'order[0][dir]': 'desc', 'order[1][column]': 333, # Unknown idx. }).json() assert response['recordsTotal'] == 5 assert response['recordsFiltered'] == 5 assert len(response['data']) == 5 assert 'custom_my ' in response['data'][0]['title_custom']
def test_source_query_set(setup_articles): source = Article.objects.filter(hidden=False) assert not Table(source).get_rows() # No articles in DB. setup_articles() assert len(Table(source).get_rows()) == 5 article = Article(title='hidden') article.save() assert len(Table(source).get_rows()) == 6 article.hidden = True article.save() table = Table(source) assert len(table.get_rows()) == 5 # Still 5 due to filtering assert table.source.row_id == 'id'
def test_unsupported_source(): with pytest.raises(SiteTablesException): Table('unsupported')
def test_source_deferred(source_listdics): table = Table() table.set_source(source_listdics) assert isinstance(table.get_rows(), list)