|
1 | 1 | # -*- coding: utf-8 -*-
|
2 |
| -# (C) Copyright IBM Corp. 2018, 2020. |
| 2 | +# (C) Copyright IBM Corp. 2020. |
3 | 3 | #
|
4 | 4 | # Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | # you may not use this file except in compliance with the License.
|
|
21 | 21 | import ibm_watson.assistant_v2
|
22 | 22 | from ibm_watson.assistant_v2 import *
|
23 | 23 |
|
24 |
| -base_url = 'https://gateway.watsonplatform.net/assistant/api' |
| 24 | +base_url = 'https://api.us-south.assistant.watson.cloud.ibm.com' |
25 | 25 |
|
26 | 26 | ##############################################################################
|
27 | 27 | # Start of Service: Sessions
|
@@ -329,6 +329,170 @@ def construct_required_body(self):
|
329 | 329 | # End of Service: Message
|
330 | 330 | ##############################################################################
|
331 | 331 |
|
| 332 | +############################################################################## |
| 333 | +# Start of Service: Logs |
| 334 | +############################################################################## |
| 335 | +# region |
| 336 | + |
| 337 | +#----------------------------------------------------------------------------- |
| 338 | +# Test Class for list_logs |
| 339 | +#----------------------------------------------------------------------------- |
| 340 | +class TestListLogs(): |
| 341 | + |
| 342 | + #-------------------------------------------------------- |
| 343 | + # Test 1: Send fake data and check response |
| 344 | + #-------------------------------------------------------- |
| 345 | + @responses.activate |
| 346 | + def test_list_logs_response(self): |
| 347 | + body = self.construct_full_body() |
| 348 | + response = fake_response_LogCollection_json |
| 349 | + send_request(self, body, response) |
| 350 | + assert len(responses.calls) == 1 |
| 351 | + |
| 352 | + #-------------------------------------------------------- |
| 353 | + # Test 2: Send only required fake data and check response |
| 354 | + #-------------------------------------------------------- |
| 355 | + @responses.activate |
| 356 | + def test_list_logs_required_response(self): |
| 357 | + # Check response with required params |
| 358 | + body = self.construct_required_body() |
| 359 | + response = fake_response_LogCollection_json |
| 360 | + send_request(self, body, response) |
| 361 | + assert len(responses.calls) == 1 |
| 362 | + |
| 363 | + #-------------------------------------------------------- |
| 364 | + # Test 3: Send empty data and check response |
| 365 | + #-------------------------------------------------------- |
| 366 | + @responses.activate |
| 367 | + def test_list_logs_empty(self): |
| 368 | + check_empty_required_params(self, fake_response_LogCollection_json) |
| 369 | + check_missing_required_params(self) |
| 370 | + assert len(responses.calls) == 0 |
| 371 | + |
| 372 | + #----------- |
| 373 | + #- Helpers - |
| 374 | + #----------- |
| 375 | + def make_url(self, body): |
| 376 | + endpoint = '/v2/assistants/{0}/logs'.format(body['assistant_id']) |
| 377 | + url = '{0}{1}'.format(base_url, endpoint) |
| 378 | + return url |
| 379 | + |
| 380 | + def add_mock_response(self, url, response): |
| 381 | + responses.add(responses.GET, |
| 382 | + url, |
| 383 | + body=json.dumps(response), |
| 384 | + status=200, |
| 385 | + content_type='application/json') |
| 386 | + |
| 387 | + def call_service(self, body): |
| 388 | + service = AssistantV2( |
| 389 | + authenticator=NoAuthAuthenticator(), |
| 390 | + version='2020-04-01', |
| 391 | + ) |
| 392 | + service.set_service_url(base_url) |
| 393 | + output = service.list_logs(**body) |
| 394 | + return output |
| 395 | + |
| 396 | + def construct_full_body(self): |
| 397 | + body = dict() |
| 398 | + body['assistant_id'] = "string1" |
| 399 | + body['sort'] = "string1" |
| 400 | + body['filter'] = "string1" |
| 401 | + body['page_limit'] = 12345 |
| 402 | + body['cursor'] = "string1" |
| 403 | + return body |
| 404 | + |
| 405 | + def construct_required_body(self): |
| 406 | + body = dict() |
| 407 | + body['assistant_id'] = "string1" |
| 408 | + return body |
| 409 | + |
| 410 | + |
| 411 | +# endregion |
| 412 | +############################################################################## |
| 413 | +# End of Service: Logs |
| 414 | +############################################################################## |
| 415 | + |
| 416 | +############################################################################## |
| 417 | +# Start of Service: UserData |
| 418 | +############################################################################## |
| 419 | +# region |
| 420 | + |
| 421 | +#----------------------------------------------------------------------------- |
| 422 | +# Test Class for delete_user_data |
| 423 | +#----------------------------------------------------------------------------- |
| 424 | +class TestDeleteUserData(): |
| 425 | + |
| 426 | + #-------------------------------------------------------- |
| 427 | + # Test 1: Send fake data and check response |
| 428 | + #-------------------------------------------------------- |
| 429 | + @responses.activate |
| 430 | + def test_delete_user_data_response(self): |
| 431 | + body = self.construct_full_body() |
| 432 | + response = fake_response__json |
| 433 | + send_request(self, body, response) |
| 434 | + assert len(responses.calls) == 1 |
| 435 | + |
| 436 | + #-------------------------------------------------------- |
| 437 | + # Test 2: Send only required fake data and check response |
| 438 | + #-------------------------------------------------------- |
| 439 | + @responses.activate |
| 440 | + def test_delete_user_data_required_response(self): |
| 441 | + # Check response with required params |
| 442 | + body = self.construct_required_body() |
| 443 | + response = fake_response__json |
| 444 | + send_request(self, body, response) |
| 445 | + assert len(responses.calls) == 1 |
| 446 | + |
| 447 | + #-------------------------------------------------------- |
| 448 | + # Test 3: Send empty data and check response |
| 449 | + #-------------------------------------------------------- |
| 450 | + @responses.activate |
| 451 | + def test_delete_user_data_empty(self): |
| 452 | + check_empty_required_params(self, fake_response__json) |
| 453 | + check_missing_required_params(self) |
| 454 | + assert len(responses.calls) == 0 |
| 455 | + |
| 456 | + #----------- |
| 457 | + #- Helpers - |
| 458 | + #----------- |
| 459 | + def make_url(self, body): |
| 460 | + endpoint = '/v2/user_data' |
| 461 | + url = '{0}{1}'.format(base_url, endpoint) |
| 462 | + return url |
| 463 | + |
| 464 | + def add_mock_response(self, url, response): |
| 465 | + responses.add(responses.DELETE, |
| 466 | + url, |
| 467 | + body=json.dumps(response), |
| 468 | + status=202, |
| 469 | + content_type='') |
| 470 | + |
| 471 | + def call_service(self, body): |
| 472 | + service = AssistantV2( |
| 473 | + authenticator=NoAuthAuthenticator(), |
| 474 | + version='2020-04-01', |
| 475 | + ) |
| 476 | + service.set_service_url(base_url) |
| 477 | + output = service.delete_user_data(**body) |
| 478 | + return output |
| 479 | + |
| 480 | + def construct_full_body(self): |
| 481 | + body = dict() |
| 482 | + body['customer_id'] = "string1" |
| 483 | + return body |
| 484 | + |
| 485 | + def construct_required_body(self): |
| 486 | + body = dict() |
| 487 | + body['customer_id'] = "string1" |
| 488 | + return body |
| 489 | + |
| 490 | + |
| 491 | +# endregion |
| 492 | +############################################################################## |
| 493 | +# End of Service: UserData |
| 494 | +############################################################################## |
| 495 | + |
332 | 496 |
|
333 | 497 | def check_empty_required_params(obj, response):
|
334 | 498 | """Test function to assert that the operation will throw an error when given empty required data
|
@@ -397,3 +561,4 @@ def send_request(obj, body, response, url=None):
|
397 | 561 | fake_response_SessionResponse_json = """{"session_id": "fake_session_id"}"""
|
398 | 562 | fake_response_MessageResponse_json = """{"output": {"generic": [], "intents": [], "entities": [], "actions": [], "debug": {"nodes_visited": [], "log_messages": [], "branch_exited": false, "branch_exited_reason": "fake_branch_exited_reason"}, "spelling": {"text": "fake_text", "original_text": "fake_original_text", "suggested_text": "fake_suggested_text"}}, "context": {"global": {"system": {"timezone": "fake_timezone", "user_id": "fake_user_id", "turn_count": 10, "locale": "fake_locale", "reference_time": "fake_reference_time"}, "session_id": "fake_session_id"}, "skills": {}}}"""
|
399 | 563 | fake_response_MessageResponseStateless_json = """{"output": {"generic": [], "intents": [], "entities": [], "actions": [], "debug": {"nodes_visited": [], "log_messages": [], "branch_exited": false, "branch_exited_reason": "fake_branch_exited_reason"}, "spelling": {"text": "fake_text", "original_text": "fake_original_text", "suggested_text": "fake_suggested_text"}}, "context": {"global": {"system": {"timezone": "fake_timezone", "user_id": "fake_user_id", "turn_count": 10, "locale": "fake_locale", "reference_time": "fake_reference_time"}, "session_id": "fake_session_id"}, "skills": {}}}"""
|
| 564 | +fake_response_LogCollection_json = """{"logs": [], "pagination": {"next_url": "fake_next_url", "matched": 7, "next_cursor": "fake_next_cursor"}}""" |
0 commit comments