fix: fix 'duplicate-code' for pylint
This commit is contained in:
parent
ad74bede04
commit
a1868e1f44
10 changed files with 233 additions and 129 deletions
|
@ -16,6 +16,7 @@ from wuttjamaican.util import resource_path
|
|||
|
||||
from wuttaweb import util as mod
|
||||
from wuttaweb.app import establish_theme
|
||||
from wuttaweb.grids import Grid
|
||||
from wuttaweb.testing import WebTestCase
|
||||
|
||||
|
||||
|
@ -665,6 +666,52 @@ class TestMakeJsonSafe(TestCase):
|
|||
)
|
||||
|
||||
|
||||
class TestRenderVueFinalize(TestCase):
|
||||
|
||||
def basic(self):
|
||||
html = mod.render_vue_finalize("wutta-grid", "WuttaGrid")
|
||||
self.assertIn("<script>", html)
|
||||
self.assertIn("Vue.component('wutta-grid', WuttaGrid)", html)
|
||||
|
||||
|
||||
class TestMakeUsersGrid(WebTestCase):
|
||||
|
||||
def test_make_users_grid(self):
|
||||
self.pyramid_config.add_route("users.view", "/users/{uuid}/view")
|
||||
self.pyramid_config.add_route("users.edit", "/users/{uuid}/edit")
|
||||
model = self.app.model
|
||||
person = model.Person(full_name="John Doe")
|
||||
self.session.add(person)
|
||||
user = model.User(username="john", person=person)
|
||||
self.session.add(user)
|
||||
self.session.commit()
|
||||
|
||||
# basic (no actions because not prvileged)
|
||||
grid = mod.make_users_grid(self.request, key="blah.users", data=person.users)
|
||||
self.assertIsInstance(grid, Grid)
|
||||
self.assertFalse(grid.linked_columns)
|
||||
self.assertFalse(grid.actions)
|
||||
|
||||
# key may be derived from route_prefix
|
||||
grid = mod.make_users_grid(self.request, route_prefix="foo")
|
||||
self.assertIsInstance(grid, Grid)
|
||||
self.assertEqual(grid.key, "foo.view.users")
|
||||
|
||||
# view + edit actions (because root)
|
||||
with patch.object(self.request, "is_root", new=True):
|
||||
grid = mod.make_users_grid(
|
||||
self.request, key="blah.users", data=person.users
|
||||
)
|
||||
self.assertIsInstance(grid, Grid)
|
||||
self.assertIn("username", grid.linked_columns)
|
||||
self.assertEqual(len(grid.actions), 2)
|
||||
self.assertEqual(grid.actions[0].key, "view")
|
||||
self.assertEqual(grid.actions[1].key, "edit")
|
||||
|
||||
# render grid to ensure coverage for link urls
|
||||
grid.render_vue_template()
|
||||
|
||||
|
||||
class TestGetAvailableThemes(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -1371,6 +1371,25 @@ class TestMasterView(WebTestCase):
|
|||
self.session.commit()
|
||||
self.assertEqual(self.session.query(model.Setting).count(), 7)
|
||||
|
||||
def test_do_thread_body(self):
|
||||
view = self.make_view()
|
||||
|
||||
# nb. so far this is just proving coverage, in case caller
|
||||
# does not specify an error handler
|
||||
|
||||
def func():
|
||||
raise RuntimeError
|
||||
|
||||
# with error handler
|
||||
onerror = MagicMock()
|
||||
view.do_thread_body(func, (), {}, onerror)
|
||||
onerror.assert_called_once_with()
|
||||
|
||||
# without error handler
|
||||
onerror.reset_mock()
|
||||
view.do_thread_body(func, (), {})
|
||||
onerror.assert_not_called()
|
||||
|
||||
def test_delete_bulk_thread(self):
|
||||
self.pyramid_config.add_route("settings", "/settings/")
|
||||
model = self.app.model
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue