Add wutta make-appdir
subcommand
This commit is contained in:
parent
5e971e4b0c
commit
13472a5ab5
9 changed files with 180 additions and 2 deletions
49
tests/commands/test_make_appdir.py
Normal file
49
tests/commands/test_make_appdir.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from unittest import TestCase
|
||||
from unittest.mock import patch
|
||||
|
||||
from wuttjamaican.conf import WuttaConfig
|
||||
from wuttjamaican.commands import Command, make_appdir
|
||||
|
||||
|
||||
class TestMakeAppDir(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.config = WuttaConfig(appname='wuttatest')
|
||||
self.command = Command(self.config, subcommands={
|
||||
'make-appdir': make_appdir.MakeAppDir,
|
||||
})
|
||||
|
||||
def test_run(self):
|
||||
|
||||
# appdir is created, and 3 subfolders added by default
|
||||
tempdir = tempfile.mkdtemp()
|
||||
appdir = os.path.join(tempdir, 'app')
|
||||
self.assertFalse(os.path.exists(appdir))
|
||||
self.command.run('make-appdir', '--path', appdir)
|
||||
self.assertTrue(os.path.exists(appdir))
|
||||
self.assertEqual(len(os.listdir(appdir)), 3)
|
||||
shutil.rmtree(tempdir)
|
||||
|
||||
# subfolders still added if appdir already exists
|
||||
tempdir = tempfile.mkdtemp()
|
||||
self.assertTrue(os.path.exists(tempdir))
|
||||
self.assertEqual(len(os.listdir(tempdir)), 0)
|
||||
self.command.run('make-appdir', '--path', tempdir)
|
||||
self.assertEqual(len(os.listdir(tempdir)), 3)
|
||||
shutil.rmtree(tempdir)
|
||||
|
||||
# mock out sys.prefix to get coverage
|
||||
with patch('wuttjamaican.commands.make_appdir.sys') as sys:
|
||||
tempdir = tempfile.mkdtemp()
|
||||
appdir = os.path.join(tempdir, 'app')
|
||||
sys.prefix = tempdir
|
||||
self.assertFalse(os.path.exists(appdir))
|
||||
self.command.run('make-appdir')
|
||||
self.assertTrue(os.path.exists(appdir))
|
||||
self.assertEqual(len(os.listdir(appdir)), 3)
|
||||
shutil.rmtree(tempdir)
|
|
@ -1,5 +1,8 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from unittest import TestCase
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
|
@ -9,18 +12,38 @@ from sqlalchemy.engine import Engine
|
|||
from sqlalchemy.pool import NullPool
|
||||
|
||||
from wuttjamaican import app, db
|
||||
from wuttjamaican.conf import WuttaConfig
|
||||
|
||||
|
||||
class TestAppHandler(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.config = MagicMock()
|
||||
self.config = WuttaConfig(appname='wuttatest')
|
||||
self.app = app.AppHandler(self.config)
|
||||
|
||||
def test_init(self):
|
||||
self.assertIs(self.app.config, self.config)
|
||||
self.assertEqual(self.app.handlers, {})
|
||||
|
||||
def test_make_appdir(self):
|
||||
|
||||
# appdir is created, and 3 subfolders added by default
|
||||
tempdir = tempfile.mkdtemp()
|
||||
appdir = os.path.join(tempdir, 'app')
|
||||
self.assertFalse(os.path.exists(appdir))
|
||||
self.app.make_appdir(appdir)
|
||||
self.assertTrue(os.path.exists(appdir))
|
||||
self.assertEqual(len(os.listdir(appdir)), 3)
|
||||
shutil.rmtree(tempdir)
|
||||
|
||||
# subfolders still added if appdir already exists
|
||||
tempdir = tempfile.mkdtemp()
|
||||
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)
|
||||
shutil.rmtree(tempdir)
|
||||
|
||||
def test_make_engine_from_config_basic(self):
|
||||
engine = self.app.make_engine_from_config({
|
||||
'sqlalchemy.url': 'sqlite://',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue