|
11 | 11 | #• Modify its title and description |
12 | 12 | #• Delete an existing validates Requirement link if it exists |
13 | 13 | #• 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' |
14 | 19 |
|
| 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 |
15 | 29 | import sys |
16 | 30 | import os |
17 | 31 | import csv |
|
38 | 52 | logger = logging.getLogger(__name__) |
39 | 53 | utils.log_commandline( os.path.basename(sys.argv[0]) ) |
40 | 54 |
|
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 | 55 |
|
56 | 56 | # caching control |
57 | 57 | # 0=fully cached (but code below specifies queries aren't cached) - if you need to clear the cache, delet efolder .web_cache |
|
105 | 105 | #• Delete an existing validates Requirement link if it exists |
106 | 106 | #• Add 2 Validated By links, 1 to a DNG requirement – 1 to a DWA requirement |
107 | 107 |
|
| 108 | +#Get the query base of the QM configuration |
108 | 109 | tcquerybase = c.get_query_capability_uri("oslc_qm:TestCaseQuery") |
109 | 110 | if not tcquerybase: |
110 | 111 | raise Exception( "TestCaseQueryBase not found !!!" ) |
| 112 | + |
| 113 | +#Put here the ID of a Test Case that exists and that has a validatedBy link |
111 | 114 | tcid = 53 |
112 | 115 | print(f"Querying test case with identifier = {tcid}") |
| 116 | + |
| 117 | +#OSLC query to get the test case with the identifier defined above |
113 | 118 | tcs = c.execute_oslc_query( |
114 | 119 | tcquerybase, |
115 | 120 | whereterms=[['rqm_qm:shortIdentifier','=',f'"{tcid}"']], |
116 | 121 | select=['*'], |
117 | 122 | prefixes={rdfxml.RDF_DEFAULT_PREFIX["rqm_qm"]:'rqm_qm'} # note this is reversed - url to prefix |
118 | 123 | ) |
119 | 124 |
|
| 125 | +#We check if we get only 1 test case in the response. |
120 | 126 | if len(tcs.items())==1: |
121 | 127 |
|
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. |
123 | 129 | print(f"Found Test Case URL: {tc_u}") |
124 | 130 | 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. |
128 | 132 | 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) |
130 | 135 | tcObject = TestCase.from_etree(xml_data) |
131 | 136 |
|
132 | 137 | #get the title and description |
133 | 138 | print(f"Test case title: {tcObject.title}") |
134 | 139 | print(f"Test case description: {tcObject.description}") |
135 | 140 | print("----------------------------------------------------------") |
136 | | - #displaying the links details |
| 141 | + #displaying the links details, links are stored in the "links" list of the TestCase object |
137 | 142 | print("Links details:") |
138 | 143 | for link in tcObject.links: |
139 | 144 | print(f" - {link.predicate} -> {link.target} (title: {link.title})") |
140 | 145 |
|
141 | 146 | print("----------------------------------------------------------") |
142 | 147 |
|
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 |
144 | 149 | tcObject.title += " added by Python" |
| 150 | + #Description can be empty so we need to check that before modifying it. |
145 | 151 | if tcObject.description is None: |
146 | 152 | tcObject.description = " added by Python" |
147 | 153 | else: |
148 | 154 | tcObject.description += " added by Python" |
149 | 155 |
|
150 | 156 |
|
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 |
152 | 158 | for link in tcObject.links: |
153 | 159 | tcObject.delete_validatesRequirementLink(link.target) |
154 | 160 | print(f"Deleting the link to {link.target}") |
|
172 | 178 |
|
173 | 179 | print("----------------------------------------------------------") |
174 | 180 |
|
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. |
176 | 182 | xml_data = tcObject.to_etree() |
177 | | - #print(ET.tostring(xml_data)) |
| 183 | + |
178 | 184 | 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 |
179 | 186 | 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" ) |
180 | 187 | if response.status_code==200: |
181 | 188 | print("Update succesfull") |
182 | 189 | else: |
183 | 190 | print("Update failed") |
184 | 191 | ##################################################################################################### |
185 | 192 |
|
| 193 | +#check if we got no test case |
186 | 194 | elif len(tcs.items())==0: |
187 | 195 | print("No test case found") |
188 | 196 |
|
| 197 | +#check if we got more than 1 test case, impossible but we handled that possibility |
189 | 198 | else: |
190 | 199 | print(f"We found more than one test case with identififer {tcid} !!!???") |
| 200 | + |
| 201 | +#end of the script |
191 | 202 | print( "Finished" ) |
0 commit comments