Quick Search:

View

Revision:

Diff

Diff from 499 to:

Annotations

Annotate by Age | Author | None
/fisheye/browse/windmill/trunk/windmill/authoring/transforms.py

Annotated File View

mikeal
226
1 #   Copyright (c) 2007 Open Source Applications Foundation
2 #
3 #   Licensed under the Apache License, Version 2.0 (the "License");
4 #   you may not use this file except in compliance with the License.
5 #   You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #   Unless required by applicable law or agreed to in writing, software
10 #   distributed under the License is distributed on an "AS IS" BASIS,
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #   See the License for the specific language governing permissions and
13 #   limitations under the License.
14
mikeal
249
15 import sys
16 import os
17 import windmill
18 import simplejson
mikeal
229
19
mikeal
226
20 def test_object_transform(test):
mikeal
454
21     """Transform test object in to controller call in python."""
mikeal
226
22     params = ', '.join([key+'='+repr(value) for key, value in test['params'].items()])    
mikeal
229
23     return 'client.%s(%s)' % (test['method'], params)
mikeal
226
24     
25 def build_test_file(tests):
mikeal
454
26     """Build the test file for python"""
mikeal
239
27     ts = '# Generated by the windmill services transformer\n'
mikeal
226
28     ts += 'from windmill.authoring import WindmillTestClient\n\n'
mikeal
283
29     ts += 'def test():\n'
mikeal
249
30     ts += '    client = WindmillTestClient(__name__)\n\n    '
mikeal
239
31     ts += '\n    '.join([test_object_transform(test) for test in tests])
mikeal
226
32     return ts
33     
34 def create_python_test_file(suite_name, tests, location=None):
mikeal
454
35     """Transform and create and build the python test file"""
mikeal
226
36     if location is None: 
37         location = os.path.join(windmill.settings['JS_PATH'], 'saves', suite_name+'.py')
mikeal
230
38     f = open(location, 'w')
mikeal
226
39     f.write(build_test_file(tests))
40     f.flush()
41     f.close()
42     return '%s/windmill-serv/saves/%s' % (windmill.settings['TEST_URL'], suite_name+'.py')
43     
44 def create_json_test_file(suite_name, tests, location=None):
mikeal
454
45     """Transform and create a json test file."""
mikeal
226
46     if location is None: 
47         location = os.path.join(windmill.settings['JS_PATH'], 'saves', suite_name+'.json')
mikeal
230
48     f = open(location, 'w')
mikeal
226
49     for test in tests:
mikeal
499
50         # Strip keys that aren't part of the api
51         test.pop('suite_name', None) ; test.pop('version', None)
mikeal
226
52         f.write(simplejson.dumps(test))
53         f.write('\n')
54     f.flush()
55     f.close()
56     return '%s/windmill-serv/saves/%s' % (windmill.settings['TEST_URL'], suite_name+'.json')
57     
58 registry = {'python':create_python_test_file, 'json':create_json_test_file}
59