-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_data.py
More file actions
118 lines (98 loc) · 3.47 KB
/
Copy pathimport_data.py
File metadata and controls
118 lines (98 loc) · 3.47 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import sys
import csv
import datetime
import django
django.setup()
from jenkins_dashboard.models import (JenkinsProject, JenkinsJob,
JenkinsTestSuite, JenkinsTestCase,
JenkinsTestBox, JenkinsResults)
PROJECT_FIELDS = {'ProjectName': 'name'}
JOB_FIELDS = {'TestJobName': 'name',
'ProjectName': 'project_id',
'TestJobExecutionId': 'execution_id',
}
SUIT_FIELDS = {'SuiteName': 'name',
'TestJobName': 'job_id'}
CASE_FIELDS = {'TestCaseID': 'name',
'SuiteName': 'suite_id',
'Author': 'author',
'TotalActions': 'total_actions',
'TotalConditions': 'total_conditions'}
BOX_FIELDS = {'BoxType': 'box_type',
'BoxUnitAddress': 'unit_address',
'BoxIP': 'ipaddress'}
RESULT_FIELDS = {'idTestResult': 'id',
'BoxIP': 'box_id',
'TestCaseID': 'case_id',
'Date': 'result_date',
'Tester': 'tester',
'FailNumbers': 'fail_numbers',
'PassNumbers': 'pass_numbers',
'Result': 'result',
'ExecutionTime': 'execution_time'
}
project_data = {}
job_data = {}
suit_data = {}
case_data = {}
box_data = {}
result_data = {}
with open(sys.argv[1]) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
project = {}
job = {}
suit = {}
case = {}
box = {}
result = {}
for key, value in row.iteritems():
if key in PROJECT_FIELDS:
project[PROJECT_FIELDS[key]] = value
if key in JOB_FIELDS:
job[JOB_FIELDS[key]] = value
if key in SUIT_FIELDS:
suit[SUIT_FIELDS[key]] = value
if key in CASE_FIELDS:
case[CASE_FIELDS[key]] = value
if key in BOX_FIELDS:
box[BOX_FIELDS[key]] = value
if key in RESULT_FIELDS:
result[RESULT_FIELDS[key]] = value
project_data[project['name']] = project
job_data[job['name']] = job
suit_data[suit['name']] = suit
case_data[case['name']] = case
box_data[box['ipaddress']] = box
result_data[result['id']] = result
for project_name, project in project_data.iteritems():
p_obj = JenkinsProject(**project)
p_obj.save()
project_data[project_name] = p_obj.id
for job_name, job in job_data.iteritems():
job['project_id'] = project_data[job['project_id']]
j_obj = JenkinsJob(**job)
j_obj.save()
job_data[job_name] = j_obj.id
for suit_name, suite in suit_data.iteritems():
suite['job_id'] = job_data[suite['job_id']]
s_obj = JenkinsTestSuite(**suite)
s_obj.save()
suit_data[suit_name] = s_obj.id
for case_name, case in case_data.iteritems():
case['suite_id'] = suit_data[case['suite_id']]
c_obj = JenkinsTestCase(**case)
c_obj.save()
case_data[case_name] = c_obj.id
for box_name, box in box_data.iteritems():
b_obj = JenkinsTestBox(**box)
b_obj.save()
box_data[box_name] = b_obj.id
for result in result_data.values():
result['case_id'] = case_data[result['case_id']]
result['box_id'] = box_data[result['box_id']]
result['id'] = int(result['id'])
result['result_date'] = \
datetime.datetime.strptime(result['result_date'], '%m/%d/%Y %H:%S')
r_obj = JenkinsResults(**result)
r_obj.save()