summaryrefslogtreecommitdiff
path: root/cgi-bin/monkey-index.cgi
blob: 756260ac746371ae3902222f2d05b60964357ff1 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3

'''
NetSurf test plan generator

The division form parameter may be given to select different groups of tests
  to include.
'''

import os
import re
import cgi
import cgitb
import yaml

cgitb.enable()

def main():
    '''
    The test plan generator
    '''
    docroot = os.environ["DOCUMENT_ROOT"]

    files = {}

    testroot = os.path.join(docroot, "monkey-test")

    params = cgi.FieldStorage()

    division = 'index'
    group_filter = None

    if 'division' in params and re.match('^[A-Za-z0-9-]+$', params['division'].value):
        division = params['division'].value

    if 'group' in params and re.match('^[A-Za-z0-9-]+$', params['group'].value):
        group_filter = params['group'].value

    print('Content-Type: text/plain')
    print('')

    # load all test plan yaml files
    for fname in os.listdir(testroot):
        if not fname.endswith(".yaml"):
            continue
        with open(os.path.join(testroot, fname), "r") as file_handle:
            files[fname] = yaml.load(file_handle)

    if division + '.yaml' not in files:
        print('# Unknown division ' + division)
        return

    for group in files[division + '.yaml']:
        if group_filter not None and group_filter != group['group']:
            continue
        print("---")
        group["kind"] = "group"
        print(yaml.dump(group, default_flow_style=False))
        for filename, content in files.items():
            if isinstance(content, dict) and content.get("group") == group["group"]:
                group_data = {"kind": "test", "filename": filename, "content": content}
                print("---")
                print(yaml.dump(group_data, default_flow_style=False))


if __name__ == "__main__":
    main()