Skip to content

Commit 9c1f8e5

Browse files
author
pridey19
committed
fix(listProviders): Addressed api definition review comments
1 parent ce9c9ee commit 9c1f8e5

File tree

4 files changed

+464
-192
lines changed

4 files changed

+464
-192
lines changed

examples/test_findings_v1_examples.py

Lines changed: 391 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,391 @@
1+
# -*- coding: utf-8 -*-
2+
# (C) Copyright IBM Corp. 2021.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
"""
17+
Examples for FindingsV1
18+
"""
19+
20+
from ibm_cloud_sdk_core import ApiException, read_external_sources
21+
from ibm_cloud_sdk_core.utils import datetime_to_string, string_to_datetime
22+
import os
23+
import pytest
24+
from ibm_scc.findings_v1 import *
25+
26+
account_id = 'testString'
27+
28+
#
29+
# This file provides an example of how to use the Findings service.
30+
#
31+
# The following configuration properties are assumed to be defined:
32+
# FINDINGS_URL=<service base url>
33+
# FINDINGS_AUTH_TYPE=iam
34+
# FINDINGS_APIKEY=<IAM apikey>
35+
# FINDINGS_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
36+
#
37+
# These configuration properties can be exported as environment variables, or stored
38+
# in a configuration file and then:
39+
# export IBM_CREDENTIALS_FILE=<name of configuration file>
40+
#
41+
config_file = 'findings_v1.env'
42+
43+
findings_service = None
44+
45+
config = None
46+
47+
48+
##############################################################################
49+
# Start of Examples for Service: FindingsV1
50+
##############################################################################
51+
# region
52+
class TestFindingsV1Examples():
53+
"""
54+
Example Test Class for FindingsV1
55+
"""
56+
57+
@classmethod
58+
def setup_class(cls):
59+
global findings_service
60+
if os.path.exists(config_file):
61+
os.environ['IBM_CREDENTIALS_FILE'] = config_file
62+
63+
# begin-common
64+
65+
findings_service = FindingsV1.new_instance(
66+
account_id=account_id
67+
)
68+
69+
# end-common
70+
assert findings_service is not None
71+
72+
# Load the configuration
73+
global config
74+
config = read_external_sources(FindingsV1.DEFAULT_SERVICE_NAME)
75+
76+
print('Setup complete.')
77+
78+
needscredentials = pytest.mark.skipif(
79+
not os.path.exists(config_file), reason="External configuration not available, skipping..."
80+
)
81+
82+
@needscredentials
83+
def test_post_graph_example(self):
84+
"""
85+
post_graph request example
86+
"""
87+
try:
88+
# begin-postGraph
89+
90+
response = findings_service.post_graph(
91+
body='testString'
92+
)
93+
94+
# end-postGraph
95+
print('\npost_graph() response status code: ', response.get_status_code())
96+
97+
except ApiException as e:
98+
pytest.fail(str(e))
99+
100+
@needscredentials
101+
def test_create_note_example(self):
102+
"""
103+
create_note request example
104+
"""
105+
try:
106+
print('\ncreate_note() result:')
107+
# begin-createNote
108+
109+
reporter_model = {
110+
'id': 'testString',
111+
'title': 'testString',
112+
}
113+
114+
api_note = findings_service.create_note(
115+
provider_id='testString',
116+
short_description='testString',
117+
long_description='testString',
118+
kind='FINDING',
119+
id='testString',
120+
reported_by=reporter_model
121+
).get_result()
122+
123+
print(json.dumps(api_note, indent=2))
124+
125+
# end-createNote
126+
127+
except ApiException as e:
128+
pytest.fail(str(e))
129+
130+
@needscredentials
131+
def test_list_notes_example(self):
132+
"""
133+
list_notes request example
134+
"""
135+
try:
136+
print('\nlist_notes() result:')
137+
# begin-listNotes
138+
139+
api_list_notes_response = findings_service.list_notes(
140+
provider_id='testString'
141+
).get_result()
142+
143+
print(json.dumps(api_list_notes_response, indent=2))
144+
145+
# end-listNotes
146+
147+
except ApiException as e:
148+
pytest.fail(str(e))
149+
150+
@needscredentials
151+
def test_get_note_example(self):
152+
"""
153+
get_note request example
154+
"""
155+
try:
156+
print('\nget_note() result:')
157+
# begin-getNote
158+
159+
api_note = findings_service.get_note(
160+
provider_id='testString',
161+
note_id='testString'
162+
).get_result()
163+
164+
print(json.dumps(api_note, indent=2))
165+
166+
# end-getNote
167+
168+
except ApiException as e:
169+
pytest.fail(str(e))
170+
171+
@needscredentials
172+
def test_update_note_example(self):
173+
"""
174+
update_note request example
175+
"""
176+
try:
177+
print('\nupdate_note() result:')
178+
# begin-updateNote
179+
180+
reporter_model = {
181+
'id': 'testString',
182+
'title': 'testString',
183+
}
184+
185+
api_note = findings_service.update_note(
186+
provider_id='testString',
187+
note_id='testString',
188+
short_description='testString',
189+
long_description='testString',
190+
kind='FINDING',
191+
id='testString',
192+
reported_by=reporter_model
193+
).get_result()
194+
195+
print(json.dumps(api_note, indent=2))
196+
197+
# end-updateNote
198+
199+
except ApiException as e:
200+
pytest.fail(str(e))
201+
202+
@needscredentials
203+
def test_get_occurrence_note_example(self):
204+
"""
205+
get_occurrence_note request example
206+
"""
207+
try:
208+
print('\nget_occurrence_note() result:')
209+
# begin-getOccurrenceNote
210+
211+
api_note = findings_service.get_occurrence_note(
212+
provider_id='testString',
213+
occurrence_id='testString'
214+
).get_result()
215+
216+
print(json.dumps(api_note, indent=2))
217+
218+
# end-getOccurrenceNote
219+
220+
except ApiException as e:
221+
pytest.fail(str(e))
222+
223+
@needscredentials
224+
def test_create_occurrence_example(self):
225+
"""
226+
create_occurrence request example
227+
"""
228+
try:
229+
print('\ncreate_occurrence() result:')
230+
# begin-createOccurrence
231+
232+
api_occurrence = findings_service.create_occurrence(
233+
provider_id='testString',
234+
note_name='testString',
235+
kind='FINDING',
236+
id='testString'
237+
).get_result()
238+
239+
print(json.dumps(api_occurrence, indent=2))
240+
241+
# end-createOccurrence
242+
243+
except ApiException as e:
244+
pytest.fail(str(e))
245+
246+
@needscredentials
247+
def test_list_occurrences_example(self):
248+
"""
249+
list_occurrences request example
250+
"""
251+
try:
252+
print('\nlist_occurrences() result:')
253+
# begin-listOccurrences
254+
255+
api_list_occurrences_response = findings_service.list_occurrences(
256+
provider_id='testString'
257+
).get_result()
258+
259+
print(json.dumps(api_list_occurrences_response, indent=2))
260+
261+
# end-listOccurrences
262+
263+
except ApiException as e:
264+
pytest.fail(str(e))
265+
266+
@needscredentials
267+
def test_list_note_occurrences_example(self):
268+
"""
269+
list_note_occurrences request example
270+
"""
271+
try:
272+
print('\nlist_note_occurrences() result:')
273+
# begin-listNoteOccurrences
274+
275+
api_list_note_occurrences_response = findings_service.list_note_occurrences(
276+
provider_id='testString',
277+
note_id='testString'
278+
).get_result()
279+
280+
print(json.dumps(api_list_note_occurrences_response, indent=2))
281+
282+
# end-listNoteOccurrences
283+
284+
except ApiException as e:
285+
pytest.fail(str(e))
286+
287+
@needscredentials
288+
def test_get_occurrence_example(self):
289+
"""
290+
get_occurrence request example
291+
"""
292+
try:
293+
print('\nget_occurrence() result:')
294+
# begin-getOccurrence
295+
296+
api_list_occurrences_response = findings_service.get_occurrence(
297+
provider_id='testString',
298+
occurrence_id='testString'
299+
).get_result()
300+
301+
print(json.dumps(api_list_occurrences_response, indent=2))
302+
303+
# end-getOccurrence
304+
305+
except ApiException as e:
306+
pytest.fail(str(e))
307+
308+
@needscredentials
309+
def test_update_occurrence_example(self):
310+
"""
311+
update_occurrence request example
312+
"""
313+
try:
314+
print('\nupdate_occurrence() result:')
315+
# begin-updateOccurrence
316+
317+
api_occurrence = findings_service.update_occurrence(
318+
provider_id='testString',
319+
occurrence_id='testString',
320+
note_name='testString',
321+
kind='FINDING',
322+
id='testString'
323+
).get_result()
324+
325+
print(json.dumps(api_occurrence, indent=2))
326+
327+
# end-updateOccurrence
328+
329+
except ApiException as e:
330+
pytest.fail(str(e))
331+
332+
@needscredentials
333+
def test_list_providers_example(self):
334+
"""
335+
list_providers request example
336+
"""
337+
try:
338+
print('\nlist_providers() result:')
339+
# begin-listProviders
340+
341+
api_list_providers_response = findings_service.list_providers().get_result()
342+
343+
print(json.dumps(api_list_providers_response, indent=2))
344+
345+
# end-listProviders
346+
347+
except ApiException as e:
348+
pytest.fail(str(e))
349+
350+
@needscredentials
351+
def test_delete_occurrence_example(self):
352+
"""
353+
delete_occurrence request example
354+
"""
355+
try:
356+
# begin-deleteOccurrence
357+
358+
response = findings_service.delete_occurrence(
359+
provider_id='testString',
360+
occurrence_id='testString'
361+
)
362+
363+
# end-deleteOccurrence
364+
print('\ndelete_occurrence() response status code: ', response.get_status_code())
365+
366+
except ApiException as e:
367+
pytest.fail(str(e))
368+
369+
@needscredentials
370+
def test_delete_note_example(self):
371+
"""
372+
delete_note request example
373+
"""
374+
try:
375+
# begin-deleteNote
376+
377+
response = findings_service.delete_note(
378+
provider_id='testString',
379+
note_id='testString'
380+
)
381+
382+
# end-deleteNote
383+
print('\ndelete_note() response status code: ', response.get_status_code())
384+
385+
except ApiException as e:
386+
pytest.fail(str(e))
387+
388+
# endregion
389+
##############################################################################
390+
# End of Examples for Service: FindingsV1
391+
##############################################################################

0 commit comments

Comments
 (0)