-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathviews.py
54 lines (44 loc) · 1.84 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging
import os
from django.conf import settings
from django.views.generic.base import TemplateView
from . import settings as dj_jas_settings
import json as simplejson
logger = logging.getLogger("django_jasmine")
class DjangoJasmineView(TemplateView):
template_name = "jasmine/index.html"
def get_context_data(self, version=None):
"""Run the jasmine tests and render index.html"""
root = settings.JASMINE_TEST_DIRECTORY
# Get all files in spec dir and subdirs
all_files = []
for curpath, dirs, files in os.walk(os.path.join(root, "spec")):
for name in files:
if not name.startswith("."):
"We want to avoid .file.js.swp and co"
curpath = curpath.replace(os.path.join(root, "spec"), "")
all_files.append(os.path.join(curpath, name))
suite = {}
# defaults
suite['js_files'] = []
suite['static_files'] = []
# load files.json if present
if os.path.exists(os.path.join(root, "files.json")):
file = open(os.path.join(root, 'files.json'), 'r')
json = file.read()
try:
json = simplejson.loads(json)
except ValueError:
logger.info("You might have a syntax error in your files.json, "
"like a surplus comma")
# Trick to call back the django handler500, couldn't find a way to
# customize the Exception Type field in the debug Traceback
json = simplejson.loads(json)
suite.update(json)
file.close()
data = {
'files': [fl for fl in all_files if fl.endswith('js')],
'suite': suite,
'version': version or dj_jas_settings.DEFAULT_JASMINE_VERSION,
}
return data