Skip to content

Commit f9eafcd

Browse files
Make testjs command more extendable
1 parent 0a1295d commit f9eafcd

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

djangular/management/commands/testjs.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99
from djangular import utils
1010
from optparse import make_option
1111

12-
DEFAULT_TYPE = 'unit'
13-
1412

1513
class Command(utils.SiteAndPathUtils, mgmt.base.BaseCommand):
1614
"""
1715
A base command that calls testacular from the command line, passing the options and arguments directly.
1816
"""
19-
requires_model_validation = False
2017
help = ("Runs the JS Testacular tests for the given test type and apps. If no apps are specified, tests will be "
2118
"run for every app in INSTALLED_APPS.")
2219
args = '[type] [appname ...]'
@@ -25,6 +22,10 @@ class Command(utils.SiteAndPathUtils, mgmt.base.BaseCommand):
2522
help="Run every app in the project, ignoring passed in apps and the INSTALLED_APPS setting. "
2623
"Note that running e2e tests for non-installed apps will most likely cause them to fail."),
2724
)
25+
requires_model_validation = False
26+
27+
default_test_type = 'unit'
28+
template_dir = 'templates'
2829

2930
def get_existing_apps_from(self, app_list):
3031
"""
@@ -53,29 +54,29 @@ def usage(self, subcommand):
5354
)
5455

5556
# Check and see if templates exist
56-
template_path = os.path.join(self.get_default_site_app(), 'templates')
57+
template_path = os.path.join(self.get_default_site_app(), self.template_dir)
5758
if os.path.exists(template_path) and os.path.isdir(template_path):
5859
filename_matches = [re.match(r'^testacular-(.*).conf.js$', filename)
5960
for filename in os.listdir(template_path)]
6061
template_types = [match.group(1) for match in filename_matches if match]
6162

6263
if len(template_types):
6364
types_message = '\n'.join(["The following types of Testacular tests are available:"] +
64-
[" %s%s" % (test_type, '*' if test_type == DEFAULT_TYPE else '')
65+
[" %s%s" % (test_type, '*' if test_type == self.default_test_type else '')
6566
for test_type in template_types] +
6667
["", "If no apps are listed, tests from all the INSTALLED_APPS will be run."])
6768

6869
# Append template message to standard usage
6970
parent_usage = super(Command, self).usage(subcommand)
7071
return "%s\n\n%s" % (parent_usage, types_message)
7172

72-
def handle(self, test_type=DEFAULT_TYPE, *args, **options):
73+
def handle(self, test_type=None, *args, **options):
7374
self.verbosity = int(options.get('verbosity'))
74-
self.test_type = test_type
75+
self.test_type = test_type or self.default_test_type
7576

7677
# Determine template location
7778
testacular_config_template = \
78-
os.path.join(self.get_default_site_app(), 'templates', 'testacular-%s.conf.js' % self.test_type)
79+
os.path.join(self.get_default_site_app(), self.template_dir, 'testacular-%s.conf.js' % self.test_type)
7980
if self.verbosity >= 2:
8081
self.stdout.write("Using testacular template: %s" % testacular_config_template)
8182

djangular/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class SiteAndPathUtils(object):
77
"""
8-
Mixing to get commonly used directories in Djangular Commands
8+
Mixin to get commonly used directories in Djangular Commands
99
"""
1010
def get_default_site_app(self):
1111
"""

0 commit comments

Comments
 (0)