def test_handle_read_actions_error(logger_mock, os_mock): def throw_error(): raise Exception("Fake Error") os_mock.side_effect = throw_error app = Pantam() app.read_actions_folder() logger_mock.assert_called_with( "Unable to read actions folder! Check `actions_folder` config setting." )
def test_load_actions(): app = Pantam() app.read_actions_folder = Mock(return_value=["index.py"]) # type: ignore app.import_action_module = Mock(return_value=MockAction) # type: ignore app.discover_actions() app.load_actions() actions = app.get_actions() assert actions[0]["action_class"] == MockAction assert isinstance(actions[0]["action_obj"], MockAction) assert actions[0]["file_name"] == "index.py" assert actions[0]["module_name"] == "index" assert actions[0]["class_name"] == "Index" assert actions[0]["routes"] == []
def test_discover_actions(): app = Pantam() app.read_actions_folder = Mock(return_value=["index.py", "auth_test.py" ]) # type: ignore actions = app.discover_actions() expected = [ { "file_name": "index.py", "module_name": "index", "class_name": "Index", "routes": [], }, { "file_name": "auth_test.py", "module_name": "auth-test", "class_name": "AuthTest", "routes": [], }, ] assert actions == expected
def test_read_actions_folder(mock): mock.return_value = ["foo.py", "bar.py", "rubbish.txt", "__init__.py"] app = Pantam() files = app.read_actions_folder() assert files == ["foo.py", "bar.py"]