Skip to content

Commit 6efe91d

Browse files
committed
chore(style): run yapf on tests
1 parent 88106fb commit 6efe91d

8 files changed

+1958
-1221
lines changed

test/unit/test_assistant_v1.py

Lines changed: 744 additions & 336 deletions
Large diffs are not rendered by default.

test/unit/test_assistant_v2.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
##############################################################################
2929
# region
3030

31+
3132
#-----------------------------------------------------------------------------
3233
# Test Class for create_session
3334
#-----------------------------------------------------------------------------
@@ -73,16 +74,16 @@ def make_url(self, body):
7374

7475
def add_mock_response(self, url, response):
7576
responses.add(responses.POST,
76-
url,
77-
body=json.dumps(response),
78-
status=201,
79-
content_type='application/json')
80-
77+
url,
78+
body=json.dumps(response),
79+
status=201,
80+
content_type='application/json')
81+
8182
def call_service(self, body):
8283
service = AssistantV2(
8384
authenticator=NoAuthAuthenticator(),
8485
version='2019-02-28',
85-
)
86+
)
8687
service.set_service_url(base_url)
8788
output = service.create_session(**body)
8889
return output
@@ -137,22 +138,23 @@ def test_delete_session_empty(self):
137138
#- Helpers -
138139
#-----------
139140
def make_url(self, body):
140-
endpoint = '/v2/assistants/{0}/sessions/{1}'.format(body['assistant_id'], body['session_id'])
141+
endpoint = '/v2/assistants/{0}/sessions/{1}'.format(
142+
body['assistant_id'], body['session_id'])
141143
url = '{0}{1}'.format(base_url, endpoint)
142144
return url
143145

144146
def add_mock_response(self, url, response):
145147
responses.add(responses.DELETE,
146-
url,
147-
body=json.dumps(response),
148-
status=200,
149-
content_type='')
150-
148+
url,
149+
body=json.dumps(response),
150+
status=200,
151+
content_type='')
152+
151153
def call_service(self, body):
152154
service = AssistantV2(
153155
authenticator=NoAuthAuthenticator(),
154156
version='2019-02-28',
155-
)
157+
)
156158
service.set_service_url(base_url)
157159
output = service.delete_session(**body)
158160
return output
@@ -180,6 +182,7 @@ def construct_required_body(self):
180182
##############################################################################
181183
# region
182184

185+
183186
#-----------------------------------------------------------------------------
184187
# Test Class for message
185188
#-----------------------------------------------------------------------------
@@ -219,22 +222,23 @@ def test_message_empty(self):
219222
#- Helpers -
220223
#-----------
221224
def make_url(self, body):
222-
endpoint = '/v2/assistants/{0}/sessions/{1}/message'.format(body['assistant_id'], body['session_id'])
225+
endpoint = '/v2/assistants/{0}/sessions/{1}/message'.format(
226+
body['assistant_id'], body['session_id'])
223227
url = '{0}{1}'.format(base_url, endpoint)
224228
return url
225229

226230
def add_mock_response(self, url, response):
227231
responses.add(responses.POST,
228-
url,
229-
body=json.dumps(response),
230-
status=200,
231-
content_type='application/json')
232-
232+
url,
233+
body=json.dumps(response),
234+
status=200,
235+
content_type='application/json')
236+
233237
def call_service(self, body):
234238
service = AssistantV2(
235239
authenticator=NoAuthAuthenticator(),
236240
version='2019-02-28',
237-
)
241+
)
238242
service.set_service_url(base_url)
239243
output = service.message(**body)
240244
return output
@@ -243,7 +247,18 @@ def construct_full_body(self):
243247
body = dict()
244248
body['assistant_id'] = "string1"
245249
body['session_id'] = "string1"
246-
body.update({"input": MessageInput._from_dict(json.loads("""{"message_type": "fake_message_type", "text": "fake_text", "options": {"debug": false, "restart": false, "alternate_intents": false, "return_context": true}, "intents": [], "entities": [], "suggestion_id": "fake_suggestion_id"}""")), "context": MessageContext._from_dict(json.loads("""{"global": {"system": {"timezone": "fake_timezone", "user_id": "fake_user_id", "turn_count": 10}}, "skills": {}}""")), })
250+
body.update({
251+
"input":
252+
MessageInput._from_dict(
253+
json.loads(
254+
"""{"message_type": "fake_message_type", "text": "fake_text", "options": {"debug": false, "restart": false, "alternate_intents": false, "return_context": true}, "intents": [], "entities": [], "suggestion_id": "fake_suggestion_id"}"""
255+
)),
256+
"context":
257+
MessageContext._from_dict(
258+
json.loads(
259+
"""{"global": {"system": {"timezone": "fake_timezone", "user_id": "fake_user_id", "turn_count": 10}}, "skills": {}}"""
260+
)),
261+
})
247262
return body
248263

249264
def construct_required_body(self):
@@ -275,6 +290,7 @@ def check_empty_required_params(obj, response):
275290
error = True
276291
assert error
277292

293+
278294
def check_missing_required_params(obj):
279295
"""Test function to assert that the operation will throw an error when missing required data
280296
@@ -291,6 +307,7 @@ def check_missing_required_params(obj):
291307
error = True
292308
assert error
293309

310+
294311
def check_empty_response(obj):
295312
"""Test function to assert that the operation will return an empty response when given an empty request
296313
@@ -302,6 +319,7 @@ def check_empty_response(obj):
302319
url = obj.make_url(body)
303320
send_request(obj, {}, {}, url=url)
304321

322+
305323
def send_request(obj, body, response, url=None):
306324
"""Test function to create a request, send it, and assert its accuracy to the mock response
307325
@@ -318,6 +336,7 @@ def send_request(obj, body, response, url=None):
318336
assert responses.calls[0].request.url.startswith(url)
319337
assert output.get_result() == response
320338

339+
321340
####################
322341
## Mock Responses ##
323342
####################

test/unit/test_common.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
from ibm_watson import get_sdk_headers
1818
import unittest
1919

20+
2021
class TestCommon(unittest.TestCase):
22+
2123
def test_get_sdk_headers(self):
2224
headers = get_sdk_headers('my_service', 'v1', 'my_operation')
2325
self.assertIsNotNone(headers)
2426
self.assertIsNotNone(headers.get('X-IBMCloud-SDK-Analytics'))
2527
self.assertIsNotNone(headers.get('User-Agent'))
2628
self.assertIn('watson-apis-python-sdk', headers.get('User-Agent'))
27-
self.assertEqual(headers.get('X-IBMCloud-SDK-Analytics'), 'service_name=my_service;service_version=v1;operation_id=my_operation')
29+
self.assertEqual(
30+
headers.get('X-IBMCloud-SDK-Analytics'),
31+
'service_name=my_service;service_version=v1;operation_id=my_operation'
32+
)

0 commit comments

Comments
 (0)