3
0
Fork 0

feat: add install handler and related logic

- Mako is now a core dependency
- therefore no more 'email' extra
- add `get_install_handler()` method for app handler
- add `render_mako_template()` method for app handler
- add `resource_path()` method for app handler
- install handler thus far can:
  - confirm db connection
  - make appdir plus config/scripts:
    - wutta.conf
    - web.conf
    - upgrade.sh
  - upgrade db schema to create tables
  - from there web app can run, create admin user
- quick start docs now describe "generated code" option
This commit is contained in:
Lance Edgar 2024-11-24 10:13:56 -06:00
parent 49e77d7407
commit ceeff7e911
15 changed files with 1526 additions and 32 deletions

View file

@ -9,9 +9,10 @@ from unittest import TestCase
from unittest.mock import patch, MagicMock
import pytest
from mako.template import Template
import wuttjamaican.enum
from wuttjamaican import app
from wuttjamaican import app as mod
from wuttjamaican.progress import ProgressBase
from wuttjamaican.conf import WuttaConfig
from wuttjamaican.util import UNSPECIFIED
@ -23,7 +24,7 @@ class TestAppHandler(FileTestCase):
def setUp(self):
self.setup_files()
self.config = WuttaConfig(appname='wuttatest')
self.app = app.AppHandler(self.config)
self.app = mod.AppHandler(self.config)
self.config.app = self.app
def test_init(self):
@ -83,7 +84,7 @@ class TestAppHandler(FileTestCase):
self.assertFalse(os.path.exists(appdir))
self.app.make_appdir(appdir)
self.assertTrue(os.path.exists(appdir))
self.assertEqual(len(os.listdir(appdir)), 3)
self.assertEqual(len(os.listdir(appdir)), 4)
shutil.rmtree(tempdir)
# subfolders still added if appdir already exists
@ -91,9 +92,28 @@ class TestAppHandler(FileTestCase):
self.assertTrue(os.path.exists(tempdir))
self.assertEqual(len(os.listdir(tempdir)), 0)
self.app.make_appdir(tempdir)
self.assertEqual(len(os.listdir(tempdir)), 3)
self.assertEqual(len(os.listdir(tempdir)), 4)
shutil.rmtree(tempdir)
def test_render_mako_template(self):
output_conf = self.write_file('output.conf', '')
template = Template("""\
[wutta]
app_title = WuttaTest
""")
output = self.app.render_mako_template(template, {}, output_path=output_conf)
self.assertEqual(output, """\
[wutta]
app_title = WuttaTest
""")
with open(output_conf, 'rt') as f:
self.assertEqual(f.read(), output)
def test_resource_path(self):
result = self.app.resource_path('wuttjamaican:templates')
self.assertEqual(result, os.path.join(os.path.dirname(mod.__file__), 'templates'))
def test_make_session(self):
try:
from wuttjamaican import db
@ -411,16 +431,17 @@ class TestAppHandler(FileTestCase):
self.assertIsInstance(auth, AuthHandler)
def test_get_email_handler(self):
try:
import mako
except ImportError:
pytest.skip("test not relevant without mako")
from wuttjamaican.email import EmailHandler
mail = self.app.get_email_handler()
self.assertIsInstance(mail, EmailHandler)
def test_get_install_handler(self):
from wuttjamaican.install import InstallHandler
install = self.app.get_install_handler()
self.assertIsInstance(install, InstallHandler)
def test_get_people_handler(self):
from wuttjamaican.people import PeopleHandler
@ -428,11 +449,6 @@ class TestAppHandler(FileTestCase):
self.assertIsInstance(people, PeopleHandler)
def test_send_email(self):
try:
import mako
except ImportError:
pytest.skip("test not relevant without mako")
from wuttjamaican.email import EmailHandler
with patch.object(EmailHandler, 'send_email') as send_email:
@ -444,13 +460,13 @@ class TestAppProvider(TestCase):
def setUp(self):
self.config = WuttaConfig(appname='wuttatest')
self.app = app.AppHandler(self.config)
self.app = mod.AppHandler(self.config)
self.config._app = self.app
def test_constructor(self):
# config object is expected
provider = app.AppProvider(self.config)
provider = mod.AppProvider(self.config)
self.assertIs(provider.config, self.config)
self.assertIs(provider.app, self.app)
self.assertEqual(provider.appname, 'wuttatest')
@ -458,13 +474,13 @@ class TestAppProvider(TestCase):
# but can pass app handler instead
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
provider = app.AppProvider(self.app)
provider = mod.AppProvider(self.app)
self.assertIs(provider.config, self.config)
self.assertIs(provider.app, self.app)
def test_get_all_providers(self):
class FakeProvider(app.AppProvider):
class FakeProvider(mod.AppProvider):
pass
# nb. we specify *classes* here
@ -482,7 +498,7 @@ class TestAppProvider(TestCase):
def test_hasattr(self):
class FakeProvider(app.AppProvider):
class FakeProvider(mod.AppProvider):
def fake_foo(self):
pass
@ -499,7 +515,7 @@ class TestAppProvider(TestCase):
# now we test that providers are loaded...
class FakeProvider(app.AppProvider):
class FakeProvider(mod.AppProvider):
def fake_foo(self):
return 42
@ -541,11 +557,11 @@ class TestGenericHandler(TestCase):
def setUp(self):
self.config = WuttaConfig(appname='wuttatest')
self.app = app.AppHandler(self.config)
self.app = mod.AppHandler(self.config)
self.config._app = self.app
def test_constructor(self):
handler = app.GenericHandler(self.config)
handler = mod.GenericHandler(self.config)
self.assertIs(handler.config, self.config)
self.assertIs(handler.app, self.app)
self.assertEqual(handler.appname, 'wuttatest')