-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_framework.py
More file actions
67 lines (53 loc) · 2.12 KB
/
test_framework.py
File metadata and controls
67 lines (53 loc) · 2.12 KB
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
from __future__ import print_function
from jinja2 import Environment, FileSystemLoader
from pprint import pprint
import argparse
import json
import requests
import os
def read_config(cfg_filename):
with open(cfg_filename) as cfg_f:
cfg = json.loads(cfg_f.read())
return cfg['pi-web-agent']['system']['actions']
def time_actions(actions, root_url):
action_times = {}
password = raw_input("Please provide the password: ")
for action, attrs in actions.iteritems():
action_url = "".join([root_url, attrs['url']])
dt = requests.get(action_url, verify=False,
auth=('admin', password)).elapsed.total_seconds()
action_times[attrs['title']] = dt
print("finished ", action_url, " in ", dt, " seconds!")
return action_times
def run_tests(config_filename, root_url):
actions = read_config(config_filename)
action_times = time_actions(actions, root_url)
return action_times
def write_results(action_times, fout_name):
env = Environment(loader=FileSystemLoader(searchpath='templates'))
template = env.get_template('results.html')
try:
os.remove(fout_name)
except OSError:
pass
with open(fout_name, "w") as fout:
fout.write(template.render(action_times=json.dumps(action_times)))
def get_parser():
parser = argparse.ArgumentParser()
parser.add_argument("-r", "--root",
help="URL for pi-web-agent",
required=True)
parser.add_argument("-o", "--fout",
help="Name for html file output",
required=False, default="results_rend.html")
parser.add_argument("-c", "--cfg",
help="Location of configuration file containing actions to test",
required=False, default="config.cfg")
return parser
def command_line_runner():
parser = get_parser()
args = parser.parse_args()
action_times = run_tests(config_filename=args.cfg, root_url=args.root)
write_results(action_times, args.fout)
if __name__ == "__main__":
command_line_runner()