9
9
from djangular import utils
10
10
from optparse import make_option
11
11
12
- DEFAULT_TYPE = 'unit'
13
-
14
12
15
13
class Command (utils .SiteAndPathUtils , mgmt .base .BaseCommand ):
16
14
"""
17
15
A base command that calls testacular from the command line, passing the options and arguments directly.
18
16
"""
19
- requires_model_validation = False
20
17
help = ("Runs the JS Testacular tests for the given test type and apps. If no apps are specified, tests will be "
21
18
"run for every app in INSTALLED_APPS." )
22
19
args = '[type] [appname ...]'
@@ -25,6 +22,10 @@ class Command(utils.SiteAndPathUtils, mgmt.base.BaseCommand):
25
22
help = "Run every app in the project, ignoring passed in apps and the INSTALLED_APPS setting. "
26
23
"Note that running e2e tests for non-installed apps will most likely cause them to fail." ),
27
24
)
25
+ requires_model_validation = False
26
+
27
+ default_test_type = 'unit'
28
+ template_dir = 'templates'
28
29
29
30
def get_existing_apps_from (self , app_list ):
30
31
"""
@@ -53,29 +54,29 @@ def usage(self, subcommand):
53
54
)
54
55
55
56
# 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 )
57
58
if os .path .exists (template_path ) and os .path .isdir (template_path ):
58
59
filename_matches = [re .match (r'^testacular-(.*).conf.js$' , filename )
59
60
for filename in os .listdir (template_path )]
60
61
template_types = [match .group (1 ) for match in filename_matches if match ]
61
62
62
63
if len (template_types ):
63
64
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 '' )
65
66
for test_type in template_types ] +
66
67
["" , "If no apps are listed, tests from all the INSTALLED_APPS will be run." ])
67
68
68
69
# Append template message to standard usage
69
70
parent_usage = super (Command , self ).usage (subcommand )
70
71
return "%s\n \n %s" % (parent_usage , types_message )
71
72
72
- def handle (self , test_type = DEFAULT_TYPE , * args , ** options ):
73
+ def handle (self , test_type = None , * args , ** options ):
73
74
self .verbosity = int (options .get ('verbosity' ))
74
- self .test_type = test_type
75
+ self .test_type = test_type or self . default_test_type
75
76
76
77
# Determine template location
77
78
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 )
79
80
if self .verbosity >= 2 :
80
81
self .stdout .write ("Using testacular template: %s" % testacular_config_template )
81
82
0 commit comments