Skip to content

Commit e9582fb

Browse files
ROMAIN BARTHROMAIN BARTH
authored andcommitted
ETM samples
1 parent 547414e commit e9582fb

File tree

3 files changed

+74
-55
lines changed

3 files changed

+74
-55
lines changed

elmclient/examples/etm_scenario1.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,21 @@
99

1010
#ETM scenario1: Run a query for all Test Case modified since 01/01/2025 -> Display their URLs, identifier and title
1111
#
12+
#parameters
13+
jazzhost = 'https://jazz.ibm.com:9443'
14+
15+
username = 'ibm'
16+
password = 'ibm'
17+
18+
jtscontext = 'jts'
19+
qmappdomain = 'qm'
1220

21+
# the project+component+config that will be queried
22+
proj = "SGC Quality Management"
23+
comp = "SGC MTM"
24+
conf = "SGC MTM Production stream"
25+
26+
#### DO NOT TOUCH elmclient initializing####### Go to scenario1
1327
import sys
1428
import os
1529
import csv
@@ -34,21 +48,6 @@
3448
logger = logging.getLogger(__name__)
3549
utils.log_commandline( os.path.basename(sys.argv[0]) )
3650

37-
#parameters
38-
jazzhost = 'https://jazz.ibm.com:9443'
39-
40-
username = 'ibm'
41-
password = 'ibm'
42-
43-
jtscontext = 'jts'
44-
qmappdomain = 'qm'
45-
46-
# the project+component+config that will be queried
47-
proj = "SGC Quality Management"
48-
comp = "SGC MTM"
49-
conf = "SGC MTM Production stream"
50-
51-
5251
# caching control
5352
# 0=fully cached (but code below specifies queries aren't cached) - if you need to clear the cache, delet efolder .web_cache
5453
# 1=clear cache initially then continue with cache enabled
@@ -95,21 +94,28 @@
9594
#####################################################################################################
9695
#SCENARIO 1
9796
# find the test cases with dcterms modified > 2025-01-01
97+
98+
#Get the query base of the QM configuration
9899
tcquerybase = c.get_query_capability_uri("oslc_qm:TestCaseQuery")
99100
if not tcquerybase:
100101
raise Exception( "TestCaseQueryBase not found !!!" )
101102

103+
# OSLC query to find all the test cases modified after the 1st of January 2025, returns dcterms:identifier, dcterms:title, rqm_qm:shortIdentifier
102104
tcs = c.execute_oslc_query(
103105
tcquerybase,
104106
whereterms=[['dcterms:modified','>','"2025-01-01T00:00:00.000Z"^^xsd:dateTime']],
105107
select=['dcterms:identifier,dcterms:title,rqm_qm:shortIdentifier'],
106108
prefixes={rdfxml.RDF_DEFAULT_PREFIX["dcterms"]:'dcterms',rdfxml.RDF_DEFAULT_PREFIX["rqm_qm"]:'rqm_qm'} # note this is reversed - url to prefix
107109
)
108110

109-
nbTC = len(tcs) #count the number of Test case returned by the query
111+
nbTC = len(tcs) #count the number of Test case returned by the query and display it
110112
print(f"The query returned {nbTC} Test Cases")
111113
print("----------------------------------------------------------")
114+
115+
#initialize a count variable to zero
112116
count = 0
117+
118+
#looping through the test cases returned by the query -> print data
113119
for TCurl in tcs:
114120
count+=1
115121
print(f"Test case #{count}")

elmclient/examples/etm_scenario2.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,21 @@
1111
#• Modify its title and description
1212
#• Delete an existing validates Requirement link if it exists
1313
#• Add 2 Validated By links, 1 to a DNG requirement – 1 to a DWA requirement
14+
#parameters
15+
jazzhost = 'https://jazz.ibm.com:9443'
16+
17+
username = 'ibm'
18+
password = 'ibm'
1419

20+
jtscontext = 'jts'
21+
qmappdomain = 'qm'
22+
23+
# the project+component+config that will be queried
24+
proj = "SGC Quality Management"
25+
comp = "SGC MTM"
26+
conf = "SGC MTM Production stream" #conf="" if project is optout
27+
28+
#### DO NOT TOUCH elmclient initializing####### Go to scenario2
1529
import sys
1630
import os
1731
import csv
@@ -38,20 +52,6 @@
3852
logger = logging.getLogger(__name__)
3953
utils.log_commandline( os.path.basename(sys.argv[0]) )
4054

41-
#parameters
42-
jazzhost = 'https://jazz.ibm.com:9443'
43-
44-
username = 'ibm'
45-
password = 'ibm'
46-
47-
jtscontext = 'jts'
48-
qmappdomain = 'qm'
49-
50-
# the project+component+config that will be queried
51-
proj = "SGC Quality Management"
52-
comp = "SGC MTM"
53-
conf = "SGC MTM Production stream" #conf="" if project is optout
54-
5555

5656
# caching control
5757
# 0=fully cached (but code below specifies queries aren't cached) - if you need to clear the cache, delet efolder .web_cache
@@ -105,50 +105,56 @@
105105
#• Delete an existing validates Requirement link if it exists
106106
#• Add 2 Validated By links, 1 to a DNG requirement – 1 to a DWA requirement
107107

108+
#Get the query base of the QM configuration
108109
tcquerybase = c.get_query_capability_uri("oslc_qm:TestCaseQuery")
109110
if not tcquerybase:
110111
raise Exception( "TestCaseQueryBase not found !!!" )
112+
113+
#Put here the ID of a Test Case that exists and that has a validatedBy link
111114
tcid = 53
112115
print(f"Querying test case with identifier = {tcid}")
116+
117+
#OSLC query to get the test case with the identifier defined above
113118
tcs = c.execute_oslc_query(
114119
tcquerybase,
115120
whereterms=[['rqm_qm:shortIdentifier','=',f'"{tcid}"']],
116121
select=['*'],
117122
prefixes={rdfxml.RDF_DEFAULT_PREFIX["rqm_qm"]:'rqm_qm'} # note this is reversed - url to prefix
118123
)
119124

125+
#We check if we get only 1 test case in the response.
120126
if len(tcs.items())==1:
121127

122-
tc_u = list(tcs.keys())[0]
128+
tc_u = list(tcs.keys())[0] #getting the test case URL, it is the first key of the list object tcs.
123129
print(f"Found Test Case URL: {tc_u}")
124130
print("Doing a Get on test case url")
125-
xml_data,etag = c.execute_get_rdf_xml( tc_u, return_etag=True)
126-
#print(ET.tostring(xml_data))
127-
131+
xml_data,etag = c.execute_get_rdf_xml( tc_u, return_etag=True) #doing a GET on the Test Case URL, with option to return the etag in order to update the test case later.
128132
print("Etag:" + etag)
129-
#put the TC data in a test case object
133+
134+
#put the TC data in a test case object (Class TestCase of the framework)
130135
tcObject = TestCase.from_etree(xml_data)
131136

132137
#get the title and description
133138
print(f"Test case title: {tcObject.title}")
134139
print(f"Test case description: {tcObject.description}")
135140
print("----------------------------------------------------------")
136-
#displaying the links details
141+
#displaying the links details, links are stored in the "links" list of the TestCase object
137142
print("Links details:")
138143
for link in tcObject.links:
139144
print(f" - {link.predicate} -> {link.target} (title: {link.title})")
140145

141146
print("----------------------------------------------------------")
142147

143-
#modifying title and description
148+
#modifying title and description, it just add the mention "added by Python" to the title and the description of the Test Case
144149
tcObject.title += " added by Python"
150+
#Description can be empty so we need to check that before modifying it.
145151
if tcObject.description is None:
146152
tcObject.description = " added by Python"
147153
else:
148154
tcObject.description += " added by Python"
149155

150156

151-
#delete an existing link
157+
#delete the first existing link (if it exists), we loop through the link, delete the first link and exit the loop with the break key word
152158
for link in tcObject.links:
153159
tcObject.delete_validatesRequirementLink(link.target)
154160
print(f"Deleting the link to {link.target}")
@@ -172,20 +178,25 @@
172178

173179
print("----------------------------------------------------------")
174180

175-
#get the data from the test case object
181+
#get the data from the test case object, needed to send the PUT update request to actually update the Test Case.
176182
xml_data = tcObject.to_etree()
177-
#print(ET.tostring(xml_data))
183+
178184
print("sending the PUT request to update the test case")
185+
#To do the PUT request, we need the Test Case URL, the updated XML data of the Test Case and the etag
179186
response = c.execute_post_rdf_xml(tc_u, data=xml_data, put=True, cacheable=False, headers={'If-Match':etag,'Content-Type':'application/rdf+xml'}, intent="Update the test case" )
180187
if response.status_code==200:
181188
print("Update succesfull")
182189
else:
183190
print("Update failed")
184191
#####################################################################################################
185192

193+
#check if we got no test case
186194
elif len(tcs.items())==0:
187195
print("No test case found")
188196

197+
#check if we got more than 1 test case, impossible but we handled that possibility
189198
else:
190199
print(f"We found more than one test case with identififer {tcid} !!!???")
200+
201+
#end of the script
191202
print( "Finished" )

elmclient/examples/etm_scenario3.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212
#• Save the test case
1313
#• Add 2 Validated By links, 1 to a DNG requirement – 1 to a DWA requirement
1414

15+
#parameters
16+
jazzhost = 'https://jazz.ibm.com:9443'
17+
18+
username = 'ibm'
19+
password = 'ibm'
20+
21+
jtscontext = 'jts'
22+
qmappdomain = 'qm'
23+
24+
# the project+component+config that will be queried
25+
proj = "SGC Quality Management"
26+
comp = "SGC MTM"
27+
conf = "SGC MTM Production stream" #conf="" if project is optout
28+
29+
#### DO NOT TOUCH elmclient initializing####### Go to scenario3
1530
import sys
1631
import os
1732
import csv
@@ -38,21 +53,6 @@
3853
logger = logging.getLogger(__name__)
3954
utils.log_commandline( os.path.basename(sys.argv[0]) )
4055

41-
#parameters
42-
jazzhost = 'https://jazz.ibm.com:9443'
43-
44-
username = 'ibm'
45-
password = 'ibm'
46-
47-
jtscontext = 'jts'
48-
qmappdomain = 'qm'
49-
50-
# the project+component+config that will be queried
51-
proj = "SGC Quality Management"
52-
comp = "SGC MTM"
53-
conf = "SGC MTM Production stream" #conf="" if project is optout
54-
55-
5656
# caching control
5757
# 0=fully cached (but code below specifies queries aren't cached) - if you need to clear the cache, delet efolder .web_cache
5858
# 1=clear cache initially then continue with cache enabled
@@ -128,13 +128,15 @@
128128
#POST request to create the new test case
129129
response = c.execute_post_rdf_xml( tc_factory_u, data=xml_data, intent="Create a test case", headers={'Referer': 'https://jazz.ibm.com:9443/qm', 'X-Jazz-CSRF-Prevent': jsessionid }, remove_parameters=['oslc_config.context'] )
130130

131+
#if response is 201, Test Case has been created succesfully
131132
if response.status_code==201:
132133
print("Test Case created succesfully")
133134
#Get the url of the new Test case created
134135
tcquerybase = c.get_query_capability_uri("oslc_qm:TestCaseQuery")
135136
if not tcquerybase:
136137
raise Exception( "TestCaseQueryBase not found !!!" )
137138

139+
#Getting the created TC to add links
138140
print(f"Querying test case with title = {tc_title}")
139141
tcs = c.execute_oslc_query(
140142
tcquerybase,

0 commit comments

Comments
 (0)