mikeal
|
226
|
1
|
|
mikeal
|
1252
|
2
|
|
mikeal
|
1253
|
3
|
|
mikeal
|
226
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
mikeal
|
249
|
17
|
import os
|
mikeal
|
1253
|
18
|
import sys
|
mikeal
|
249
|
19
|
import windmill
|
mikeal
|
953
|
20
|
try:
|
|
21
|
import json as simplejson
|
|
22
|
except:
|
|
23
|
import simplejson
|
mikeal
|
520
|
24
|
import tempfile
|
mikeal
|
229
|
25
|
|
mikeal
|
1253
|
26
|
if not sys.version.startswith('2.4'):
|
|
27
|
from urlparse import urlparse
|
|
28
|
else:
|
|
29
|
|
|
30
|
from windmill.tools.urlparse_25 import urlparse
|
|
31
|
|
mikeal
|
1118
|
32
|
|
|
33
|
def get_save_url(suite_name, extension):
|
|
34
|
url = urlparse(windmill.settings['TEST_URL'])
|
|
35
|
return url.scheme+'://'+url.netloc+'/windmill-saves/'+suite_name+'.'+extension
|
|
36
|
|
mikeal
|
520
|
37
|
def create_saves_path():
|
|
38
|
directory = tempfile.mkdtemp(suffix='.windmill-saves')
|
|
39
|
|
mikeal
|
1387
|
40
|
from windmill.dep import wsgi_fileserver
|
|
41
|
WSGIFileServerApplication = wsgi_fileserver.WSGIFileServerApplication
|
mikeal
|
520
|
42
|
application = WSGIFileServerApplication(root_path=os.path.abspath(directory), mount_point='/windmill-saves/')
|
mikeal
|
1387
|
43
|
from windmill.server import wsgi
|
mikeal
|
520
|
44
|
wsgi.add_namespace('windmill-saves', application)
|
|
45
|
windmill.settings['SAVES_PATH'] = directory
|
|
46
|
windmill.teardown_directories.append(directory)
|
|
47
|
|
mikeal
|
1133
|
48
|
def test_object_transform_to_python(test):
|
mikeal
|
454
|
49
|
"""Transform test object in to controller call in python."""
|
mikeal
|
226
|
50
|
params = ', '.join([key+'='+repr(value) for key, value in test['params'].items()])
|
mikeal
|
229
|
51
|
return 'client.%s(%s)' % (test['method'], params)
|
mikeal
|
226
|
52
|
|
mikeal
|
1133
|
53
|
def build_python_test_file(tests, suite_name=None):
|
mikeal
|
454
|
54
|
"""Build the test file for python"""
|
mikeal
|
239
|
55
|
ts = '# Generated by the windmill services transformer\n'
|
mikeal
|
226
|
56
|
ts += 'from windmill.authoring import WindmillTestClient\n\n'
|
mikeal
|
948
|
57
|
if suite_name:
|
|
58
|
ts += 'def test_'+suite_name.replace('test_', '', 1)+'():\n'
|
|
59
|
else:
|
|
60
|
ts += 'def test():\n'
|
mikeal
|
249
|
61
|
ts += ' client = WindmillTestClient(__name__)\n\n '
|
mikeal
|
1133
|
62
|
ts += '\n '.join([test_object_transform_to_python(test) for test in tests])
|
mikeal
|
226
|
63
|
return ts
|
|
64
|
|
|
65
|
def create_python_test_file(suite_name, tests, location=None):
|
mikeal
|
454
|
66
|
"""Transform and create and build the python test file"""
|
mikeal
|
226
|
67
|
if location is None:
|
mikeal
|
507
|
68
|
location = os.path.join(windmill.settings['SAVES_PATH'], suite_name+'.py')
|
mikeal
|
230
|
69
|
f = open(location, 'w')
|
mikeal
|
1175
|
70
|
f.write(build_python_test_file(tests, suite_name.split('.')[0]))
|
mikeal
|
226
|
71
|
f.flush()
|
|
72
|
f.close()
|
mikeal
|
1118
|
73
|
return get_save_url(suite_name, 'py')
|
mikeal
|
1133
|
74
|
|
mikeal
|
226
|
75
|
def create_json_test_file(suite_name, tests, location=None):
|
mikeal
|
454
|
76
|
"""Transform and create a json test file."""
|
mikeal
|
226
|
77
|
if location is None:
|
mikeal
|
507
|
78
|
location = os.path.join(windmill.settings['SAVES_PATH'], suite_name+'.json')
|
mikeal
|
230
|
79
|
f = open(location, 'w')
|
mikeal
|
226
|
80
|
for test in tests:
|
mikeal
|
499
|
81
|
|
|
82
|
test.pop('suite_name', None) ; test.pop('version', None)
|
mikeal
|
226
|
83
|
f.write(simplejson.dumps(test))
|
|
84
|
f.write('\n')
|
|
85
|
f.flush()
|
|
86
|
f.close()
|
mikeal
|
1118
|
87
|
return get_save_url(suite_name, 'json')
|
mikeal
|
1133
|
88
|
|
|
89
|
def test_object_transform_to_javascript(test):
|
|
90
|
"""Transform test object in to controller call in javascript."""
|
|
91
|
test = dict([(k, v,) for k, v in test.items() if k == 'method' or k == 'params'])
|
|
92
|
return simplejson.dumps(test)
|
|
93
|
|
|
94
|
def build_javascript_test_file(tests, suite_name=None):
|
|
95
|
"""Build the test file for javascript"""
|
admc
|
1145
|
96
|
ts = '// Generated by the windmill services transformer\n'
|
mikeal
|
1133
|
97
|
if suite_name:
|
mikeal
|
1175
|
98
|
ts += 'var test_'+suite_name.replace('test_', '', 1).split('.')[0]+' = new function() {\n'
|
mikeal
|
1133
|
99
|
else:
|
|
100
|
ts += 'var test_one = new function() {\n'
|
|
101
|
ts += ' this.test_actions = [\n'
|
|
102
|
ts += ',\n'.join([test_object_transform_to_javascript(test) for test in tests])
|
|
103
|
ts += '\n ];\n'
|
|
104
|
ts += '}\n'
|
|
105
|
return ts
|
|
106
|
|
|
107
|
def create_javascript_test_file(suite_name, tests, location=None):
|
|
108
|
"""Transform and create and build the javascript test file"""
|
|
109
|
if location is None:
|
|
110
|
location = os.path.join(windmill.settings['SAVES_PATH'], suite_name+'.js')
|
|
111
|
f = open(location, 'w')
|
|
112
|
f.write(build_javascript_test_file(tests, suite_name))
|
|
113
|
f.flush()
|
|
114
|
f.close()
|
|
115
|
return get_save_url(suite_name, 'js')
|
mikeal
|
226
|
116
|
|
mikeal
|
1133
|
117
|
registry = {'python':create_python_test_file, 'json':create_json_test_file, 'javascript': create_javascript_test_file}
|
mikeal
|
226
|
118
|
|