33import hashlib
44import base64
55
6-
76class TestDialog :
8-
97 # Initialization of Dialog object with all parameters
108 def test_initialization_with_all_parameters (self ):
119 from datetime import datetime
@@ -84,43 +82,6 @@ def test_initialization_with_missing_optional_parameters(self):
8482 assert dialog .originator is None
8583 assert dialog .mimetype is None
8684
87- def test_initialization_with_missing_optional_parameters (self ):
88- # Given
89- from datetime import datetime
90- from src .vcon .dialog import Dialog
91-
92- dialog = Dialog (
93- type = "audio" ,
94- start = datetime .now (),
95- duration = None ,
96- parties = [1 , 2 ],
97- originator = None ,
98- mimetype = None ,
99- filename = None ,
100- body = None ,
101- encoding = None ,
102- url = None ,
103- alg = None ,
104- signature = None ,
105- disposition = None ,
106- party_history = None ,
107- transferee = None ,
108- transferor = None ,
109- transfer_target = None ,
110- original = None ,
111- consultation = None ,
112- target_dialog = None ,
113- campaign = None ,
114- interaction = None ,
115- skill = None
116- )
117-
118- # When & Then
119- assert dialog .type == "audio"
120- assert dialog .duration is None
121- assert dialog .originator is None
122- assert dialog .mimetype is None
123-
12485 def test_initialization_with_default_optional_parameters (self ):
12586 # Given
12687 from datetime import datetime
@@ -172,141 +133,6 @@ def test_retrieve_dialog_mimetype_when_set(self):
172133 # When & Then
173134 assert dialog .mimetype == "video/mp4"
174135
175- def test_initialization_with_missing_optional_parameters (self ):
176- # Given
177- from datetime import datetime
178- from src .vcon .dialog import Dialog
179-
180- dialog = Dialog (
181- type = "audio" ,
182- start = datetime .now (),
183- duration = None ,
184- parties = [1 , 2 ],
185- originator = None ,
186- mimetype = None ,
187- filename = None ,
188- body = None ,
189- encoding = None ,
190- url = None ,
191- alg = None ,
192- signature = None ,
193- disposition = None ,
194- party_history = None ,
195- transferee = None ,
196- transferor = None ,
197- transfer_target = None ,
198- original = None ,
199- consultation = None ,
200- target_dialog = None ,
201- campaign = None ,
202- interaction = None ,
203- skill = None
204- )
205-
206- # When
207- # Then
208- assert dialog .type == "audio"
209- assert dialog .duration is None
210- assert dialog .originator is None
211- assert dialog .mimetype is None
212-
213- def test_initialization_with_default_optional_parameters (self ):
214- # Given
215- from datetime import datetime
216- from src .vcon .dialog import Dialog
217-
218- dialog = Dialog (
219- type = "video" ,
220- start = datetime .now (),
221- duration = 0.0 ,
222- parties = [1 ],
223- originator = 1
224- )
225-
226- # When
227- # Then
228- assert dialog .duration == 0.0
229- assert dialog .parties == [1 ]
230- assert dialog .originator == 1
231-
232- # Initialization of Dialog object with all parameters
233- def test_initialization_with_all_parameters (self ):
234- from datetime import datetime
235- from src .vcon .dialog import Dialog
236- from src .vcon .party import PartyHistory
237-
238- # Given
239- party_history = [PartyHistory (1 , "join" , datetime .now ())]
240- dialog = Dialog (
241- type = "text" ,
242- start = datetime .now (),
243- duration = 120.0 ,
244- parties = [1 , 2 ],
245- originator = 1 ,
246- mimetype = "text/plain" ,
247- filename = "example.txt" ,
248- body = "Hello, World!" ,
249- encoding = "utf-8" ,
250- url = "http://example.com" ,
251- alg = "sha256" ,
252- signature = "signature" ,
253- disposition = "inline" ,
254- party_history = party_history ,
255- transferee = 2 ,
256- transferor = 1 ,
257- transfer_target = 3 ,
258- original = 1 ,
259- consultation = 2 ,
260- target_dialog = 3 ,
261- campaign = "campaign1" ,
262- interaction = "interaction1" ,
263- skill = "skill1"
264- )
265-
266- # When & Then
267- assert dialog .type == "text"
268- assert dialog .duration == 120.0
269- assert dialog .parties == [1 , 2 ]
270- assert dialog .party_history == party_history
271-
272- # Initialization with missing optional parameters
273- def test_initialization_with_missing_optional_parameters (self ):
274- from datetime import datetime
275- from src .vcon .dialog import Dialog
276-
277- # Given
278- dialog = Dialog (
279- type = "audio" ,
280- start = datetime .now (),
281- duration = None ,
282- parties = [1 , 2 ],
283- originator = None ,
284- mimetype = None ,
285- filename = None ,
286- body = None ,
287- encoding = None ,
288- url = None ,
289- alg = None ,
290- signature = None ,
291- disposition = None ,
292- party_history = None ,
293- transferee = None ,
294- transferor = None ,
295- transfer_target = None ,
296- original = None ,
297- consultation = None ,
298- target_dialog = None ,
299- campaign = None ,
300- interaction = None ,
301- skill = None
302- )
303-
304- # When & Then
305- assert dialog .type == "audio"
306- assert dialog .duration is None
307- assert dialog .originator is None
308- assert dialog .mimetype is None
309-
310136 # Conversion of Dialog object to dictionary
311137 def test_conversion_to_dict (self ):
312138 # Given
@@ -363,19 +189,19 @@ def test_fetch_external_data_success(self, mocker):
363189 response_mock .headers = {"Content-Type" : "text/plain" }
364190 response_mock .text = "sample data"
365191 mocker .patch ("requests.get" , return_value = response_mock )
366-
192+
367193 # Act
368194 dialog .add_external_data (url , filename , mimetype )
369-
195+
370196 # Assert
371197 assert dialog .mimetype == "text/plain"
372198 assert dialog .filename == filename
373199 assert dialog .alg == "sha256"
374200 assert dialog .encoding == "base64url"
375201 expected_signature = base64 .urlsafe_b64encode (hashlib .sha256 ("sample data" .encode ()).digest ()).decode ()
376202 assert dialog .signature == expected_signature
377- assert dialog .body == None
378-
203+ assert dialog .body is None
204+
379205 # URL returns a non-200 status code
380206 def test_fetch_external_data_failure (self , mocker ):
381207 # Arrange
@@ -386,13 +212,13 @@ def test_fetch_external_data_failure(self, mocker):
386212 response_mock = mocker .Mock ()
387213 response_mock .status_code = 404
388214 mocker .patch ("requests.get" , return_value = response_mock )
389-
215+
390216 # Act & Assert
391217 with pytest .raises (Exception ) as excinfo :
392218 dialog .add_external_data (url , filename , mimetype )
393-
219+
394220 assert str (excinfo .value ) == "Failed to fetch external data: 404"
395-
221+
396222 # Correctly sets the mimetype from the response headers
397223 def test_correctly_sets_mimetype (self , mocker ):
398224 # Setup
@@ -411,7 +237,7 @@ def test_correctly_sets_mimetype(self, mocker):
411237
412238 # Assert
413239 assert dialog .mimetype == mimetype
414-
240+
415241 # Overrides the filename if provided
416242 def test_overrides_filename_if_provided (self , mocker ):
417243 # Setup
@@ -432,29 +258,29 @@ def test_overrides_filename_if_provided(self, mocker):
432258
433259 # Assert
434260 assert dialog .filename == new_filename
435-
261+
436262 # Correctly sets body, filename, and mimetype attributes
437263 def test_correctly_sets_attributes (self ):
438264 dialog = Dialog (type = "text" , start = "2023-06-01T10:00:00Z" , parties = [0 ])
439265 body = "sample body"
440266 filename = "sample.txt"
441267 mimetype = "text/plain"
442-
268+
443269 dialog .add_inline_data (body , filename , mimetype )
444-
270+
445271 assert dialog .body == body
446272 assert dialog .filename == filename
447273 assert dialog .mimetype == mimetype
448-
274+
449275 # Handles empty string for body
450276 def test_handles_empty_body (self ):
451277 dialog = Dialog (type = "text" , start = "2023-06-01T10:00:00Z" , parties = [0 ])
452278 body = ""
453279 filename = "empty.txt"
454280 mimetype = "text/plain"
455-
281+
456282 dialog .add_inline_data (body , filename , mimetype )
457-
283+
458284 assert dialog .body == body
459285 assert dialog .filename == filename
460286 assert dialog .mimetype == mimetype
@@ -465,21 +291,21 @@ def test_handles_empty_body(self):
465291 def test_valid_sha256_signature (self ):
466292 # Initialize the dialog object
467293 dialog = Dialog (type = "text" , start = "2023-06-01T10:00:00Z" , parties = [0 ])
468-
294+
469295 # Add inline data
470296 dialog .add_inline_data ("example_body" , "example_filename" , "text/plain" )
471-
297+
472298 # Check if the SHA-256 hash signature is valid
473299 expected_signature = base64 .urlsafe_b64encode (hashlib .sha256 ("example_body" .encode ()).digest ()).decode ()
474300 assert dialog .signature == expected_signature
475-
301+
476302 # Sets the encoding to "base64url"
477303 def test_encoding_base64url (self ):
478304 # Initialize the dialog object
479305 dialog = Dialog (type = "text" , start = "2023-06-01T10:00:00Z" , parties = [0 ])
480-
306+
481307 # Add inline data
482308 dialog .add_inline_data ("example_body" , "example_filename" , "text/plain" )
483-
309+
484310 # Check if the encoding is set to "base64url"
485- assert dialog .encoding == "base64url"
311+ assert dialog .encoding == "base64url"
0 commit comments