8
from argparse import ArgumentParser
10
from qakit.practitest import practitest
11
from qakit.practitest.report_subunit_results_to_practitest import _read_config
14
def steps_for_test(sheet, test_name):
15
# Find the test steps in the sheet
18
for row in range(1, sheet.nrows):
19
row_values = sheet.row(row)
20
if row_values[1].value == test_name:
21
steps += ' {}.'.format(step_number)
23
if row_values[3].value:
24
for line in row_values[3].value.split('\n'):
27
steps += ' ' + line + '\n'
28
if row_values[4].value:
29
for line in row_values[4].value.split('\n'):
32
steps += ' ' + line + '\n'
36
parser = ArgumentParser(
37
'Create a Checkbox provider from a Practitest testset'
39
parser.add_argument('testset', help='The ID of the testset to use.')
43
help='Generate whitelist instead' # REMOVE
45
args = parser.parse_args()
46
# These are the instances that haven't been run
47
pt = practitest.PractitestSession(
48
**_read_config(os.path.join(os.path.dirname(__name__), 'config.ini'))
50
instances = pt.get_instances(args.testset)
51
notrun = [instance for instance in instances if instance['run_status']['value'] not in ('PASSED','FAILED')]
52
# This does the test step export
53
export = pt.get_export(410)
54
url = export.json()['url']
55
tempdir = tempfile.mkdtemp()
56
r = urllib.request.urlretrieve(url, os.path.join(tempdir, 'steps.zip'))
57
# Now we extract the spreadsheet from the zip
58
stepszip = open(r[0], 'rb')
59
z = zipfile.ZipFile(stepszip)
61
for name in z.namelist():
62
if name.endswith('.xlsx'):
63
z.extract(name, tempdir)
64
xlsx = os.path.join(tempdir, name)
65
# Now we open the spreadsheet and get the tests sheet
66
sheet = xlrd.open_workbook(xlsx).sheets()[0]
67
# First we create the provider file
68
with open(os.path.join(tempdir, 'practitest.provider'), 'w') as provider:
69
provider.write("""[PlainBox Provider]
70
description = The Practitest provider
72
name = 2015.com.canonical:qa-practitest
73
version = 1.0""".format(tempdir))
74
# Now we create the jobs and whitelist
75
if not os.path.exists(os.path.join(tempdir, 'jobs')):
76
os.makedirs(os.path.join(tempdir, 'jobs'))
77
if not os.path.exists(os.path.join(tempdir, 'whitelists')):
78
os.makedirs(os.path.join(tempdir, 'whitelists'))
79
jobs = open(os.path.join(tempdir, 'jobs', 'practitest.txt'), 'w')
81
os.path.join(tempdir, 'whitelists', 'practitest.whitelist'), 'w'
85
[c for c in test['name'] if c.isalnum() or c is ' ']
87
cb_id = 'practitest/{}/{}'.format(
88
'-'.join([word.lower() for word in test_name.split()]),
91
whitelist.write(cb_id + '\n')
92
jobs.write('plugin: manual\n')
93
jobs.write('id: {}\n'.format(cb_id))
94
jobs.write('summary: {}\n'.format(test['name']))
95
jobs.write('description:\n')
96
jobs.write(steps_for_test(sheet, test['name']))
102
if __name__ == "__main__":