|
15 | 15 | import json |
16 | 16 | import responses |
17 | 17 | import watson_developer_cloud |
| 18 | +from watson_developer_cloud import WatsonException |
18 | 19 |
|
19 | 20 | platform_url = 'https://gateway.watsonplatform.net' |
20 | 21 | service_path = '/conversation/api' |
@@ -48,6 +49,46 @@ def test_create_counterexample(): |
48 | 49 | assert responses.calls[0].request.url.startswith(url) |
49 | 50 | assert counterexample == response |
50 | 51 |
|
| 52 | +@responses.activate |
| 53 | +def test_rate_limit_exceeded(): |
| 54 | + endpoint = '/v1/workspaces/{0}/counterexamples'.format('boguswid') |
| 55 | + url = '{0}{1}'.format(base_url, endpoint) |
| 56 | + error_code = "'code': '407'" |
| 57 | + error_msg = 'Rate limit exceeded' |
| 58 | + responses.add( |
| 59 | + responses.POST, |
| 60 | + url, |
| 61 | + body='Rate limit exceeded', |
| 62 | + status=407, |
| 63 | + content_type='application/json') |
| 64 | + service = watson_developer_cloud.ConversationV1( |
| 65 | + username='username', password='password', version='2017-02-03') |
| 66 | + try: |
| 67 | + service.create_counterexample( |
| 68 | + workspace_id='boguswid', text='I want financial advice today.') |
| 69 | + except WatsonException as ex: |
| 70 | + assert len(responses.calls) == 1 |
| 71 | + assert error_code in str(ex) |
| 72 | + assert error_msg in str(ex) |
| 73 | + |
| 74 | +@responses.activate |
| 75 | +def test_unknown_error(): |
| 76 | + endpoint = '/v1/workspaces/{0}/counterexamples'.format('boguswid') |
| 77 | + url = '{0}{1}'.format(base_url, endpoint) |
| 78 | + error_msg = 'Unknown error' |
| 79 | + responses.add( |
| 80 | + responses.POST, |
| 81 | + url, |
| 82 | + status=407, |
| 83 | + content_type='application/json') |
| 84 | + service = watson_developer_cloud.ConversationV1( |
| 85 | + username='username', password='password', version='2017-02-03') |
| 86 | + try: |
| 87 | + service.create_counterexample( |
| 88 | + workspace_id='boguswid', text='I want financial advice today.') |
| 89 | + except WatsonException as ex: |
| 90 | + assert len(responses.calls) == 1 |
| 91 | + assert error_msg in str(ex) |
51 | 92 |
|
52 | 93 | @responses.activate |
53 | 94 | def test_delete_counterexample(): |
|
0 commit comments