3
0
Fork 0
wuttaweb/tests/views/test_tables.py

54 lines
1.5 KiB
Python
Raw Normal View History

# -*- coding: utf-8; -*-
from unittest.mock import patch
from wuttaweb.testing import WebTestCase
from wuttaweb.views import tables as mod
class TestUpgradeView(WebTestCase):
def make_view(self):
return mod.TableView(self.request)
def test_includeme(self):
self.pyramid_config.include("wuttaweb.views.tables")
def test_get_grid_data(self):
view = self.make_view()
data = view.get_grid_data()
self.assertIsInstance(data, list)
self.assertGreater(len(data), 0)
table = data[0]
self.assertIsInstance(table, dict)
self.assertIn("name", table)
self.assertIn("schema", table)
def test_configure_grid(self):
view = self.make_view()
# sanity / coverage check
grid = view.make_grid(columns=["name", "schema"])
view.configure_grid(grid)
def test_get_instance(self):
view = self.make_view()
with patch.object(self.request, "matchdict", new={"name": "person"}):
table1 = view.get_instance()
self.assertIsInstance(table1, dict)
self.assertIn("name", table1)
self.assertEqual(table1["name"], "person")
self.assertIn("schema", table1)
table2 = view.get_instance()
self.assertIs(table2, table1)
self.assertEqual(table2["name"], "person")
def test_get_instance_title(self):
view = self.make_view()
table = {"name": "poser_foo"}
self.assertEqual(view.get_instance_title(table), "poser_foo")