UPD: try to make useful test stuff.
This commit is contained in:
@@ -98,8 +98,11 @@ class ModuleConfig(object):
|
||||
|
||||
self._modules = dict()
|
||||
|
||||
with open(path, 'r') as f:
|
||||
data = json.load(f)
|
||||
if os.path.exists(path):
|
||||
with open(path, 'r') as f:
|
||||
data = json.load(f)
|
||||
else:
|
||||
data = dict()
|
||||
|
||||
if 'modules' in data:
|
||||
for meta_dict in data['modules']:
|
||||
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import pkg_resources
|
||||
import posix
|
||||
import sys
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
from dav_base.config.modules import DJANGO_MAIN_MODULE, ModuleConfig
|
||||
|
||||
@@ -27,6 +28,25 @@ class AdminCommand(object):
|
||||
subparser.add_argument('path', metavar='PATH',
|
||||
help='A directory, where the project files will be installed.')
|
||||
|
||||
subparser = subparsers.add_parser('enable_module',
|
||||
help='Enable a modular app within your django-dav installation.')
|
||||
subparser.add_argument('path', metavar='PATH',
|
||||
help='The directory, where your django project files are installed.')
|
||||
subparser.add_argument('module', metavar='MODULE',
|
||||
help='The name of the module.')
|
||||
|
||||
subparser = subparsers.add_parser('disable_module',
|
||||
help='Disable a modular app within your django-dav installation.')
|
||||
subparser.add_argument('path', metavar='PATH',
|
||||
help='The directory, where your django project files are installed.')
|
||||
subparser.add_argument('module', metavar='MODULE',
|
||||
help='The name of the module.')
|
||||
|
||||
subparser = subparsers.add_parser('list_modules',
|
||||
help='List enabled modular apps within your django-dav installation.')
|
||||
subparser.add_argument('path', metavar='PATH',
|
||||
help='The directory, where your django project files are installed.')
|
||||
|
||||
return parser
|
||||
|
||||
def _parse_args(self, argv=None):
|
||||
@@ -91,6 +111,32 @@ class AdminCommand(object):
|
||||
|
||||
return posix.EX_OK
|
||||
|
||||
def _subcmd_enable_module(self, cmd_args):
|
||||
django_main_module = DJANGO_MAIN_MODULE
|
||||
django_base_dir = cmd_args.path
|
||||
module_name = cmd_args.module
|
||||
sys.path.append(django_base_dir)
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = '{}.settings'.format(django_main_module)
|
||||
execute_from_command_line(['manage.py', 'enable_module', module_name])
|
||||
return posix.EX_OK
|
||||
|
||||
def _subcmd_disable_module(self, cmd_args):
|
||||
django_main_module = DJANGO_MAIN_MODULE
|
||||
django_base_dir = cmd_args.path
|
||||
module_name = cmd_args.module
|
||||
sys.path.append(django_base_dir)
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = '{}.settings'.format(django_main_module)
|
||||
execute_from_command_line(['manage.py', 'disable_module', module_name])
|
||||
return posix.EX_OK
|
||||
|
||||
def _subcmd_list_modules(self, cmd_args):
|
||||
django_main_module = DJANGO_MAIN_MODULE
|
||||
django_base_dir = cmd_args.path
|
||||
sys.path.append(django_base_dir)
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = '{}.settings'.format(django_main_module)
|
||||
execute_from_command_line(['manage.py', 'list_modules'])
|
||||
return posix.EX_OK
|
||||
|
||||
def __init__(self):
|
||||
self._argparser = self._setup_argparser()
|
||||
|
||||
|
||||
@@ -11,11 +11,13 @@ class ViewsTestCase(SimpleTestCase):
|
||||
self.assertIn('dav_base/root.html', template_names)
|
||||
context = view.get_context_data()
|
||||
self.assertIn('root_urls', context)
|
||||
self.assertIsInstance(context['root_urls'], list)
|
||||
|
||||
def test_integrated_root(self):
|
||||
response = self.client.get('/')
|
||||
self.assertTemplateUsed(response, 'dav_base/root.html')
|
||||
self.assertIn('root_urls', response.context, '\'root_urls\' not in context of root view')
|
||||
self.assertIsInstance(response.context['root_urls'], list)
|
||||
|
||||
# TODO
|
||||
# Maybe we should set a defined module config, so we could
|
||||
|
||||
Reference in New Issue
Block a user