Skip to content

Commit

Permalink
black and flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
shawncrawley committed Oct 17, 2024
1 parent 9122f42 commit 305a910
Show file tree
Hide file tree
Showing 9 changed files with 550 additions and 43 deletions.
14 changes: 9 additions & 5 deletions tests/unit_tests/test_tethys_apps/test_base/test_page_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_global_page_controller(
"title",
"custom_css",
"custom_js",
"extras"
"extras",
],
)
self.assertEqual(render_context["app"], "app object")
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_page_component_wrapper__layout_none(self):
return_value = page_handler.page_component_wrapper(app, user, layout, component)

self.assertEqual(return_value, component_return_val)

def test_page_component_wrapper__layout_none_with_extras(self):
# FUNCTION ARGS
app = mock.MagicMock()
Expand All @@ -116,7 +116,9 @@ def test_page_component_wrapper__layout_none_with_extras(self):
component_return_val = "rendered_component"
component.return_value = component_return_val

return_value = page_handler.page_component_wrapper(app, user, layout, component, extras)
return_value = page_handler.page_component_wrapper(
app, user, layout, component, extras
)

self.assertEqual(return_value, component_return_val)
component.assert_called_once_with(extra1="val1", extra2=2)
Expand All @@ -140,7 +142,7 @@ def test_page_component_wrapper__layout_not_none(self):
{"app": app, "user": user, "nav-links": app.navigation_links},
component_return_val,
)

def test_page_component_wrapper__layout_not_none_with_extras(self):
# FUNCTION ARGS
app = mock.MagicMock()
Expand All @@ -154,7 +156,9 @@ def test_page_component_wrapper__layout_not_none_with_extras(self):
component_return_val = "rendered_component"
component.return_value = component_return_val

return_value = page_handler.page_component_wrapper(app, user, layout, component, extras)
return_value = page_handler.page_component_wrapper(
app, user, layout, component, extras
)

self.assertEqual(return_value, layout_return_val)
layout.assert_called_once_with(
Expand Down
47 changes: 24 additions & 23 deletions tests/unit_tests/test_tethys_components/test_custom.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from tethys_components import custom
from tethys_components.library import Library as lib
from unittest import TestCase, mock, IsolatedAsyncioTestCase
from unittest import mock, IsolatedAsyncioTestCase
from importlib import reload
import asyncio


class TestCustomComponents(IsolatedAsyncioTestCase):
@classmethod
def setUpClass(cls):
mock.patch('reactpy.component', new_callable=lambda: lambda x: x).start()
mock.patch("reactpy.component", new_callable=lambda: lambda x: x).start()
reload(custom)

@classmethod
def tearDownClass(cls):
mock.patch.stopall()
Expand All @@ -20,9 +19,9 @@ def tearDownClass(cls):
def test_Panel_defaults(self):
test_component = custom.Panel({})
self.assertIsInstance(test_component, dict)
self.assertIn('tagName', test_component)
self.assertIn('attributes', test_component)
self.assertIn('children', test_component)
self.assertIn("tagName", test_component)
self.assertIn("attributes", test_component)
self.assertIn("children", test_component)

async def test_Panel_all_props_provided(self):
test_set_show = mock.MagicMock()
Expand All @@ -31,36 +30,38 @@ async def test_Panel_all_props_provided(self):
"set-show": test_set_show,
"position": "right",
"extent": "30vw",
"name": "Test Panel 123"
"name": "Test Panel 123",
}
test_component = custom.Panel(props)
self.assertIsInstance(test_component, dict)
self.assertIn('tagName', test_component)
self.assertIn('attributes', test_component)
self.assertIn('children', test_component)
self.assertIn("tagName", test_component)
self.assertIn("attributes", test_component)
self.assertIn("children", test_component)
test_set_show.assert_not_called()
event_handler = test_component['children'][0]['children'][1]['eventHandlers']['on_click']
event_handler = test_component["children"][0]["children"][1]["eventHandlers"][
"on_click"
]
self.assertTrue(callable(event_handler.function))
await event_handler.function([None])
test_set_show.assert_called_once_with(False)

def test_HeaderButton(self):
test_component = custom.HeaderButton({})
self.assertIsInstance(test_component, dict)
self.assertIn('tagName', test_component)
self.assertIn('attributes', test_component)
self.assertIn("tagName", test_component)
self.assertIn("attributes", test_component)

def test_NavIcon(self):
test_component = custom.NavIcon('test_src', 'test_color')
test_component = custom.NavIcon("test_src", "test_color")
self.assertIsInstance(test_component, dict)
self.assertIn('tagName', test_component)
self.assertIn('attributes', test_component)
self.assertIn("tagName", test_component)
self.assertIn("attributes", test_component)

def test_NavMenu(self):
test_component = custom.NavMenu({})
self.assertIsInstance(test_component, dict)
self.assertIn('tagName', test_component)
self.assertIn('children', test_component)
self.assertIn("tagName", test_component)
self.assertIn("children", test_component)

def test_HeaderWithNavBar(self):
custom.lib.hooks = mock.MagicMock()
Expand All @@ -70,15 +71,15 @@ def test_HeaderWithNavBar(self):
test_nav_links = [mock.MagicMock(), mock.MagicMock(), mock.MagicMock()]
test_component = custom.HeaderWithNavBar(test_app, test_user, test_nav_links)
self.assertIsInstance(test_component, dict)
self.assertIn('tagName', test_component)
self.assertIn('attributes', test_component)
self.assertIn('children', test_component)
self.assertIn("tagName", test_component)
self.assertIn("attributes", test_component)
self.assertIn("children", test_component)
del custom.lib.hooks

def test_get_db_object(self):
test_app = mock.MagicMock()
return_val = custom.get_db_object(test_app)
self.assertEqual(return_val, test_app.db_object)

def test_hooks(self):
custom.lib.hooks # should not fail
12 changes: 7 additions & 5 deletions tests/unit_tests/test_tethys_components/test_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class TestComponentLayouts(TestCase):

@mock.patch("tethys_components.layouts.HeaderWithNavBar", return_value={})
def test_NavHeader(self, _):
test_layout = layouts.NavHeader({
'app': mock.MagicMock(),
'user': mock.MagicMock(),
'nav-links': mock.MagicMock()
})
test_layout = layouts.NavHeader(
{
"app": mock.MagicMock(),
"user": mock.MagicMock(),
"nav-links": mock.MagicMock(),
}
)
self.assertIsInstance(test_layout, Component)
self.assertIsInstance(test_layout.render(), dict)
9 changes: 5 additions & 4 deletions tests/unit_tests/test_tethys_components/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ def test_use_workspace(self, mock_inspect):
mock_stack_item_1 = mock.MagicMock()
mock_stack_item_1.__getitem__().f_code.co_filename = "throws_exception"
mock_stack_item_2 = mock.MagicMock()
mock_stack_item_2.__getitem__().f_code.co_filename = str(
TEST_APP_DIR
)
mock_stack_item_2.__getitem__().f_code.co_filename = str(TEST_APP_DIR)
mock_inspect.stack.return_value = [mock_stack_item_1, mock_stack_item_2]
workspace = utils.use_workspace("john")
self.assertEqual(
mock_import.call_args_list[-1][0][0], "reactpy_django.hooks"
)
self.assertEqual(mock_import.call_args_list[-1][0][3][0], "use_memo")
mock_import().use_memo.assert_called_once()
self.assertIn('<function use_workspace.<locals>.<lambda> at', str(mock_import().use_memo.call_args_list[0]))
self.assertIn(
"<function use_workspace.<locals>.<lambda> at",
str(mock_import().use_memo.call_args_list[0]),
)
self.assertEqual(workspace, mock_import().use_memo())
finally:
mock.patch.stopall()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

# Fixes the Cache-Control error in tests. Must appear before view imports.
mock.patch("django.views.decorators.cache.never_cache", lambda x: x).start()
if 'tethys_portal.views.accounts' in sys.modules:
del sys.modules['tethys_portal.views.accounts']
if "tethys_portal.views.accounts" in sys.modules:
del sys.modules["tethys_portal.views.accounts"]

from tethys_portal.views.accounts import login_view, register, logout_view # noqa: E402

Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_tethys_portal/test_views/test_psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
mock.patch("django.views.decorators.cache.never_cache", lambda x: x).start()
mock.patch("social_django.utils.psa", side_effect=mock_decorator).start()

if 'tethys_portal.views.psa' in sys.modules:
del sys.modules['tethys_portal.views.psa']
if "tethys_portal.views.psa" in sys.modules:
del sys.modules["tethys_portal.views.psa"]

from tethys_portal.views.psa import tenant, auth, complete # noqa: E402

Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_tethys_portal/test_views/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# Fixes the Cache-Control error in tests. Must appear before view imports.
mock.patch("django.views.decorators.cache.never_cache", lambda x: x).start()
if 'tethys_portal.views.user' in sys.modules:
del sys.modules['tethys_portal.views.user']
if "tethys_portal.views.user" in sys.modules:
del sys.modules["tethys_portal.views.user"]

from tethys_portal.views.user import ( # noqa: E402
profile,
Expand Down
Loading

0 comments on commit 305a910

Please sign in to comment.