28
28
##############################################################################
29
29
# region
30
30
31
+
31
32
#-----------------------------------------------------------------------------
32
33
# Test Class for create_session
33
34
#-----------------------------------------------------------------------------
@@ -73,16 +74,16 @@ def make_url(self, body):
73
74
74
75
def add_mock_response (self , url , response ):
75
76
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
+
81
82
def call_service (self , body ):
82
83
service = AssistantV2 (
83
84
authenticator = NoAuthAuthenticator (),
84
85
version = '2019-02-28' ,
85
- )
86
+ )
86
87
service .set_service_url (base_url )
87
88
output = service .create_session (** body )
88
89
return output
@@ -137,22 +138,23 @@ def test_delete_session_empty(self):
137
138
#- Helpers -
138
139
#-----------
139
140
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' ])
141
143
url = '{0}{1}' .format (base_url , endpoint )
142
144
return url
143
145
144
146
def add_mock_response (self , url , response ):
145
147
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
+
151
153
def call_service (self , body ):
152
154
service = AssistantV2 (
153
155
authenticator = NoAuthAuthenticator (),
154
156
version = '2019-02-28' ,
155
- )
157
+ )
156
158
service .set_service_url (base_url )
157
159
output = service .delete_session (** body )
158
160
return output
@@ -180,6 +182,7 @@ def construct_required_body(self):
180
182
##############################################################################
181
183
# region
182
184
185
+
183
186
#-----------------------------------------------------------------------------
184
187
# Test Class for message
185
188
#-----------------------------------------------------------------------------
@@ -219,22 +222,23 @@ def test_message_empty(self):
219
222
#- Helpers -
220
223
#-----------
221
224
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' ])
223
227
url = '{0}{1}' .format (base_url , endpoint )
224
228
return url
225
229
226
230
def add_mock_response (self , url , response ):
227
231
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
+
233
237
def call_service (self , body ):
234
238
service = AssistantV2 (
235
239
authenticator = NoAuthAuthenticator (),
236
240
version = '2019-02-28' ,
237
- )
241
+ )
238
242
service .set_service_url (base_url )
239
243
output = service .message (** body )
240
244
return output
@@ -243,7 +247,18 @@ def construct_full_body(self):
243
247
body = dict ()
244
248
body ['assistant_id' ] = "string1"
245
249
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
+ })
247
262
return body
248
263
249
264
def construct_required_body (self ):
@@ -275,6 +290,7 @@ def check_empty_required_params(obj, response):
275
290
error = True
276
291
assert error
277
292
293
+
278
294
def check_missing_required_params (obj ):
279
295
"""Test function to assert that the operation will throw an error when missing required data
280
296
@@ -291,6 +307,7 @@ def check_missing_required_params(obj):
291
307
error = True
292
308
assert error
293
309
310
+
294
311
def check_empty_response (obj ):
295
312
"""Test function to assert that the operation will return an empty response when given an empty request
296
313
@@ -302,6 +319,7 @@ def check_empty_response(obj):
302
319
url = obj .make_url (body )
303
320
send_request (obj , {}, {}, url = url )
304
321
322
+
305
323
def send_request (obj , body , response , url = None ):
306
324
"""Test function to create a request, send it, and assert its accuracy to the mock response
307
325
@@ -318,6 +336,7 @@ def send_request(obj, body, response, url=None):
318
336
assert responses .calls [0 ].request .url .startswith (url )
319
337
assert output .get_result () == response
320
338
339
+
321
340
####################
322
341
## Mock Responses ##
323
342
####################
0 commit comments