|
| 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 CaseManagementV1 |
| 18 | +""" |
| 19 | + |
| 20 | +import os |
| 21 | +import pytest |
| 22 | +from ibm_cloud_sdk_core import ApiException, read_external_sources |
| 23 | +from ibm_platform_services.case_management_v1 import * |
| 24 | + |
| 25 | +# Config file name |
| 26 | +config_file = 'case_management_v1.env' |
| 27 | + |
| 28 | +case_management_service = None |
| 29 | + |
| 30 | +config = None |
| 31 | + |
| 32 | + |
| 33 | +############################################################################## |
| 34 | +# Start of Examples for Service: CaseManagementV1 |
| 35 | +############################################################################## |
| 36 | +# region |
| 37 | +class TestCaseManagementV1Examples(): |
| 38 | + """ |
| 39 | + Example Test Class for CaseManagementV1 |
| 40 | + """ |
| 41 | + |
| 42 | + @classmethod |
| 43 | + def setup_class(cls): |
| 44 | + global case_management_service |
| 45 | + if os.path.exists(config_file): |
| 46 | + os.environ['IBM_CREDENTIALS_FILE'] = config_file |
| 47 | + |
| 48 | + # begin-common |
| 49 | + |
| 50 | + case_management_service = CaseManagementV1.new_instance( |
| 51 | + ) |
| 52 | + |
| 53 | + # end-common |
| 54 | + assert case_management_service is not None |
| 55 | + |
| 56 | + # Load the configuration |
| 57 | + global config |
| 58 | + config = read_external_sources(CaseManagementV1.DEFAULT_SERVICE_NAME) |
| 59 | + |
| 60 | + print('Setup complete.') |
| 61 | + |
| 62 | + needscredentials = pytest.mark.skipif( |
| 63 | + not os.path.exists(config_file), reason="External configuration not available, skipping..." |
| 64 | + ) |
| 65 | + |
| 66 | + @needscredentials |
| 67 | + def test_get_cases_example(self): |
| 68 | + """ |
| 69 | + get_cases request example |
| 70 | + """ |
| 71 | + try: |
| 72 | + # begin-getCases |
| 73 | + |
| 74 | + case_list = case_management_service.get_cases().get_result() |
| 75 | + |
| 76 | + print(json.dumps(case_list, indent=2)) |
| 77 | + |
| 78 | + # end-getCases |
| 79 | + |
| 80 | + except ApiException as e: |
| 81 | + pytest.fail(str(e)) |
| 82 | + |
| 83 | + @needscredentials |
| 84 | + def test_create_case_example(self): |
| 85 | + """ |
| 86 | + create_case request example |
| 87 | + """ |
| 88 | + try: |
| 89 | + # begin-createCase |
| 90 | + |
| 91 | + case = case_management_service.create_case( |
| 92 | + type='technical', |
| 93 | + subject='testString', |
| 94 | + description='testString' |
| 95 | + ).get_result() |
| 96 | + |
| 97 | + print(json.dumps(case, indent=2)) |
| 98 | + |
| 99 | + # end-createCase |
| 100 | + |
| 101 | + except ApiException as e: |
| 102 | + pytest.fail(str(e)) |
| 103 | + |
| 104 | + @needscredentials |
| 105 | + def test_get_case_example(self): |
| 106 | + """ |
| 107 | + get_case request example |
| 108 | + """ |
| 109 | + try: |
| 110 | + # begin-getCase |
| 111 | + |
| 112 | + case = case_management_service.get_case( |
| 113 | + case_number='testString' |
| 114 | + ).get_result() |
| 115 | + |
| 116 | + print(json.dumps(case, indent=2)) |
| 117 | + |
| 118 | + # end-getCase |
| 119 | + |
| 120 | + except ApiException as e: |
| 121 | + pytest.fail(str(e)) |
| 122 | + |
| 123 | + @needscredentials |
| 124 | + def test_update_case_status_example(self): |
| 125 | + """ |
| 126 | + update_case_status request example |
| 127 | + """ |
| 128 | + try: |
| 129 | + # begin-updateCaseStatus |
| 130 | + |
| 131 | + status_payload_model = { |
| 132 | + 'action': 'resolve', |
| 133 | + 'comment': 'It was actually a mistake', |
| 134 | + 'resolution_code': 1 |
| 135 | + } |
| 136 | + |
| 137 | + case = case_management_service.update_case_status( |
| 138 | + case_number='testString', |
| 139 | + status_payload=status_payload_model |
| 140 | + ).get_result() |
| 141 | + |
| 142 | + print(json.dumps(case, indent=2)) |
| 143 | + |
| 144 | + # end-updateCaseStatus |
| 145 | + |
| 146 | + except ApiException as e: |
| 147 | + pytest.fail(str(e)) |
| 148 | + |
| 149 | + @needscredentials |
| 150 | + def test_add_comment_example(self): |
| 151 | + """ |
| 152 | + add_comment request example |
| 153 | + """ |
| 154 | + try: |
| 155 | + # begin-addComment |
| 156 | + |
| 157 | + comment = case_management_service.add_comment( |
| 158 | + case_number='testString', |
| 159 | + comment='This is a test comment' |
| 160 | + ).get_result() |
| 161 | + |
| 162 | + print(json.dumps(comment, indent=2)) |
| 163 | + |
| 164 | + # end-addComment |
| 165 | + |
| 166 | + except ApiException as e: |
| 167 | + pytest.fail(str(e)) |
| 168 | + |
| 169 | + @needscredentials |
| 170 | + def test_add_watchlist_example(self): |
| 171 | + """ |
| 172 | + add_watchlist request example |
| 173 | + """ |
| 174 | + try: |
| 175 | + # begin-addWatchlist |
| 176 | + |
| 177 | + watchlist_add_response = case_management_service.add_watchlist( |
| 178 | + case_number='testString', |
| 179 | + ).get_result() |
| 180 | + |
| 181 | + print(json.dumps(watchlist_add_response, indent=2)) |
| 182 | + |
| 183 | + # end-addWatchlist |
| 184 | + |
| 185 | + except ApiException as e: |
| 186 | + pytest.fail(str(e)) |
| 187 | + |
| 188 | + @needscredentials |
| 189 | + def test_add_resource_example(self): |
| 190 | + """ |
| 191 | + add_resource request example |
| 192 | + """ |
| 193 | + try: |
| 194 | + # begin-addResource |
| 195 | + |
| 196 | + resource = case_management_service.add_resource( |
| 197 | + case_number='testString', |
| 198 | + ).get_result() |
| 199 | + |
| 200 | + print(json.dumps(resource, indent=2)) |
| 201 | + |
| 202 | + # end-addResource |
| 203 | + |
| 204 | + except ApiException as e: |
| 205 | + pytest.fail(str(e)) |
| 206 | + |
| 207 | + @needscredentials |
| 208 | + def test_upload_file_example(self): |
| 209 | + """ |
| 210 | + upload_file request example |
| 211 | + """ |
| 212 | + try: |
| 213 | + # begin-uploadFile |
| 214 | + |
| 215 | + file_with_metadata_model = { |
| 216 | + 'data': io.BytesIO(b'This is a mock file.').getvalue() |
| 217 | + } |
| 218 | + |
| 219 | + attachment = case_management_service.upload_file( |
| 220 | + case_number='testString', |
| 221 | + file=[file_with_metadata_model] |
| 222 | + ).get_result() |
| 223 | + |
| 224 | + print(json.dumps(attachment, indent=2)) |
| 225 | + |
| 226 | + # end-uploadFile |
| 227 | + |
| 228 | + except ApiException as e: |
| 229 | + pytest.fail(str(e)) |
| 230 | + |
| 231 | + @needscredentials |
| 232 | + def test_download_file_example(self): |
| 233 | + """ |
| 234 | + download_file request example |
| 235 | + """ |
| 236 | + try: |
| 237 | + # begin-downloadFile |
| 238 | + |
| 239 | + result = case_management_service.download_file( |
| 240 | + case_number='testString', |
| 241 | + file_id='testString' |
| 242 | + ).get_result() |
| 243 | + |
| 244 | + with open('/tmp/result.out', 'wb') as fp: |
| 245 | + fp.write(result) |
| 246 | + |
| 247 | + # end-downloadFile |
| 248 | + |
| 249 | + except ApiException as e: |
| 250 | + pytest.fail(str(e)) |
| 251 | + |
| 252 | + @needscredentials |
| 253 | + def test_remove_watchlist_example(self): |
| 254 | + """ |
| 255 | + remove_watchlist request example |
| 256 | + """ |
| 257 | + try: |
| 258 | + # begin-removeWatchlist |
| 259 | + |
| 260 | + watchlist = case_management_service.remove_watchlist( |
| 261 | + case_number='testString', |
| 262 | + ).get_result() |
| 263 | + |
| 264 | + print(json.dumps(watchlist, indent=2)) |
| 265 | + |
| 266 | + # end-removeWatchlist |
| 267 | + |
| 268 | + except ApiException as e: |
| 269 | + pytest.fail(str(e)) |
| 270 | + |
| 271 | + @needscredentials |
| 272 | + def test_delete_file_example(self): |
| 273 | + """ |
| 274 | + delete_file request example |
| 275 | + """ |
| 276 | + try: |
| 277 | + # begin-deleteFile |
| 278 | + |
| 279 | + attachment_list = case_management_service.delete_file( |
| 280 | + case_number='testString', |
| 281 | + file_id='testString' |
| 282 | + ).get_result() |
| 283 | + |
| 284 | + print(json.dumps(attachment_list, indent=2)) |
| 285 | + |
| 286 | + # end-deleteFile |
| 287 | + |
| 288 | + except ApiException as e: |
| 289 | + pytest.fail(str(e)) |
| 290 | + |
| 291 | +# endregion |
| 292 | +############################################################################## |
| 293 | +# End of Examples for Service: CaseManagementV1 |
| 294 | +############################################################################## |
0 commit comments