-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReqImport_WithRelationship.py
More file actions
61 lines (43 loc) · 3.08 KB
/
ReqImport_WithRelationship.py
File metadata and controls
61 lines (43 loc) · 3.08 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
# This script allows you to import all your requirements from an csv file including all the Parent/Child relationship
# To import it to valispace, you just need one end of the relationship, either the Parents pointing to the Children, or the Children pointing to the Parents
# The csv file must have headers and you need to adtapt the code to the respective headers it has.
import valispace
import csv, json
deployment = input("Deployment Name:")
username = input("Username: ")
password = input("Password: ")
valispace = valispace.API(url="https://"+deployment+".valispace.com/", username=username, password=password)
## Add File path e.g. - Make sure you use /, not \, to divide folders
csvFilePath = ".../RequirementsFile.csv"
# Id of the specification the requirements will be added to
specification_ID = 33933
# How are the Parent/Children are separated in the csv. E.g.: Children: "Req-005, Req-006"; the separator is ","
separator = ","
# Variable that holds a mapping from the Requirement Identifier to the object ID in Valispace.
ReqMapping = {}
def import_req(csvFilePath, specification_ID):
# First run populates Valispace with all requirements, withouth relationship
with open(csvFilePath, encoding="utf8") as csvFile:
csvReader = csv.DictReader(csvFile)
for rows in csvReader:
req = {
"specification": specification_ID,
"identifier" : rows['IDENTIFIER'], # Replace 'IDENTIFIER' with the header title you have on the file where you have the Identifiers
"title" : rows['TITLE'], # Optional: Replace 'TITLE' with the header title you have on the file where you have the Req. Title
"text" : rows['TEXT'] # Replace 'TEXT' with the header title you have on the file where you have the Req. Text
}
requirementPosted = valispace.post('requirements/', req)
ReqMapping[req["identifier"]] = requirementPosted["id"]
# Second run populates all the relationship - Populating from the Parents to the child
# If you would like to use a column that defines the parents only, change the child filds
# ToDo: Write a Function for either Parents or Child.
with open(csvFilePath, encoding="utf8") as csvFile:
csvReader = csv.DictReader(csvFile)
for rows in csvReader:
currentReqId = ReqMapping[rows['IDENTIFIER']]
if rows['CHILDREN'] != "":
children = rows['CHILDREN'].split(separator) # Replace 'CHILDREN' with the header title you have on the file where you have the children of the requirement
for child in children:
childId = ReqMapping[child.lstrip()]
valispace.request('PUT', 'requirements/'+str(currentReqId)+'/add-child/', {"child": childId})
import_req(csvFilePath, specification_ID)