source: mod_gnutls/test/https-test-client.py @ d762813

asyncioproxy-ticket
Last change on this file since d762813 was 42097fb, checked in by Fiona Klute <fiona.klute@…>, 17 months ago

https-test-client.py: Add --timeout parameter for TEST_QUERY_TIMEOUT

  • Property mode set to 100755
File size: 2.0 KB
Line 
1#!/usr/bin/python3
2# PYTHON_ARGCOMPLETE_OK
3
4# Copyright 2019 Fiona Klute
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18import yaml
19
20from mgstest.tests import TestConnection
21
22if __name__ == "__main__":
23    import argparse
24    parser = argparse.ArgumentParser(
25        description='Send HTTP requests through gnutls-cli',
26        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
27    parser.add_argument('host', nargs='?', help='Access the specified host',
28                        default='localhost')
29    parser.add_argument('-p', '--port', type=int,
30                        help='Access the specified port', default='8000')
31    parser.add_argument('--timeout', type=float,
32                        help='Timeout for HTTP requests', default='5.0')
33    parser.add_argument('--test-config', type=argparse.FileType('r'),
34                        required=True, help='load YAML test configuration')
35
36    # enable bash completion if argcomplete is available
37    try:
38        import argcomplete
39        argcomplete.autocomplete(parser)
40    except ImportError:
41        pass
42
43    args = parser.parse_args()
44
45    conns = None
46
47    config = yaml.load(args.test_config, Loader=yaml.Loader)
48    if type(config) is TestConnection:
49        conns = [config]
50    elif type(config) is list:
51        # assume list elements are connections
52        conns = config
53    else:
54        raise TypeError(f'Unsupported configuration: {config!r}')
55    print(conns)
56
57    for test_conn in conns:
58        test_conn.run(host=args.host, port=args.port, timeout=args.timeout)
Note: See TracBrowser for help on using the repository browser.