|
21 | 21 | LayoutStylesheetError,
|
22 | 22 | NoAudioOrVideoError,
|
23 | 23 | )
|
| 24 | +from vonage_video.models.archive import Transcription |
24 | 25 |
|
25 | 26 | from testutils import build_response, get_mock_jwt_auth
|
26 | 27 |
|
@@ -409,3 +410,244 @@ def test_change_archive_layout():
|
409 | 410 |
|
410 | 411 | assert archive.id == '5b1521e6-115f-4efd-bed9-e527b87f0699'
|
411 | 412 | assert video.http_client.last_response.status_code == 200
|
| 413 | + |
| 414 | + |
| 415 | +# Tests for new Transcription options |
| 416 | +def test_transcription_model_with_all_options(): |
| 417 | + """Test that the Transcription model can be created with all new options.""" |
| 418 | + transcription = Transcription( |
| 419 | + status="completed", |
| 420 | + reason="transcription completed successfully", |
| 421 | + url="https://example.com/transcription.json", |
| 422 | + primaryLanguageCode="en-US", |
| 423 | + hasSummary=True |
| 424 | + ) |
| 425 | + |
| 426 | + assert transcription.status == "completed" |
| 427 | + assert transcription.reason == "transcription completed successfully" |
| 428 | + assert transcription.url == "https://example.com/transcription.json" |
| 429 | + assert transcription.primaryLanguageCode == "en-US" |
| 430 | + assert transcription.hasSummary is True |
| 431 | + |
| 432 | + |
| 433 | +def test_transcription_model_with_partial_options(): |
| 434 | + """Test that the Transcription model can be created with only some new options.""" |
| 435 | + transcription = Transcription( |
| 436 | + status="processing", |
| 437 | + url="https://example.com/transcription.json" |
| 438 | + ) |
| 439 | + |
| 440 | + assert transcription.status == "processing" |
| 441 | + assert transcription.url == "https://example.com/transcription.json" |
| 442 | + assert transcription.primaryLanguageCode is None |
| 443 | + assert transcription.hasSummary is None |
| 444 | + assert transcription.reason is None |
| 445 | + |
| 446 | + |
| 447 | +def test_transcription_model_with_url_only(): |
| 448 | + """Test that the Transcription model can be created with just the url option.""" |
| 449 | + transcription = Transcription( |
| 450 | + url="https://example.com/transcription.json" |
| 451 | + ) |
| 452 | + |
| 453 | + assert transcription.url == "https://example.com/transcription.json" |
| 454 | + assert transcription.status is None |
| 455 | + assert transcription.reason is None |
| 456 | + assert transcription.primaryLanguageCode is None |
| 457 | + assert transcription.hasSummary is None |
| 458 | + |
| 459 | + |
| 460 | +def test_transcription_model_with_primary_language_code_only(): |
| 461 | + """Test that the Transcription model can be created with just the primaryLanguageCode option.""" |
| 462 | + transcription = Transcription( |
| 463 | + primaryLanguageCode="es-ES" |
| 464 | + ) |
| 465 | + |
| 466 | + assert transcription.primaryLanguageCode == "es-ES" |
| 467 | + assert transcription.status is None |
| 468 | + assert transcription.reason is None |
| 469 | + assert transcription.url is None |
| 470 | + assert transcription.hasSummary is None |
| 471 | + |
| 472 | + |
| 473 | +def test_transcription_model_with_has_summary_only(): |
| 474 | + """Test that the Transcription model can be created with just the hasSummary option.""" |
| 475 | + transcription = Transcription( |
| 476 | + hasSummary=False |
| 477 | + ) |
| 478 | + |
| 479 | + assert transcription.hasSummary is False |
| 480 | + assert transcription.status is None |
| 481 | + assert transcription.reason is None |
| 482 | + assert transcription.url is None |
| 483 | + assert transcription.primaryLanguageCode is None |
| 484 | + |
| 485 | + |
| 486 | +def test_transcription_model_empty(): |
| 487 | + """Test that the Transcription model can be created with no options set.""" |
| 488 | + transcription = Transcription() |
| 489 | + |
| 490 | + assert transcription.status is None |
| 491 | + assert transcription.reason is None |
| 492 | + assert transcription.url is None |
| 493 | + assert transcription.primaryLanguageCode is None |
| 494 | + assert transcription.hasSummary is None |
| 495 | + |
| 496 | + |
| 497 | +def test_transcription_model_serialization(): |
| 498 | + """Test that the Transcription model serializes correctly.""" |
| 499 | + transcription = Transcription( |
| 500 | + status="completed", |
| 501 | + reason="success", |
| 502 | + url="https://example.com/transcription.json", |
| 503 | + primaryLanguageCode="en-US", |
| 504 | + hasSummary=True |
| 505 | + ) |
| 506 | + |
| 507 | + serialized = transcription.model_dump() |
| 508 | + expected = { |
| 509 | + "status": "completed", |
| 510 | + "reason": "success", |
| 511 | + "url": "https://example.com/transcription.json", |
| 512 | + "primaryLanguageCode": "en-US", |
| 513 | + "hasSummary": True |
| 514 | + } |
| 515 | + |
| 516 | + assert serialized == expected |
| 517 | + |
| 518 | + |
| 519 | +def test_transcription_model_serialization_exclude_unset(): |
| 520 | + """Test that the Transcription model serializes correctly excluding unset values.""" |
| 521 | + transcription = Transcription( |
| 522 | + url="https://example.com/transcription.json", |
| 523 | + hasSummary=True |
| 524 | + ) |
| 525 | + |
| 526 | + serialized = transcription.model_dump(exclude_unset=True) |
| 527 | + expected = { |
| 528 | + "url": "https://example.com/transcription.json", |
| 529 | + "hasSummary": True |
| 530 | + } |
| 531 | + |
| 532 | + assert serialized == expected |
| 533 | + assert "status" not in serialized |
| 534 | + assert "reason" not in serialized |
| 535 | + assert "primaryLanguageCode" not in serialized |
| 536 | + |
| 537 | + |
| 538 | +def test_transcription_model_deserialization(): |
| 539 | + """Test that the Transcription model can be created from dictionary data.""" |
| 540 | + data = { |
| 541 | + "status": "completed", |
| 542 | + "reason": "transcription finished", |
| 543 | + "url": "https://example.com/transcription.json", |
| 544 | + "primaryLanguageCode": "fr-FR", |
| 545 | + "hasSummary": True |
| 546 | + } |
| 547 | + |
| 548 | + transcription = Transcription(**data) |
| 549 | + |
| 550 | + assert transcription.status == "completed" |
| 551 | + assert transcription.reason == "transcription finished" |
| 552 | + assert transcription.url == "https://example.com/transcription.json" |
| 553 | + assert transcription.primaryLanguageCode == "fr-FR" |
| 554 | + assert transcription.hasSummary is True |
| 555 | + |
| 556 | + |
| 557 | +def test_transcription_model_with_various_language_codes(): |
| 558 | + """Test that the Transcription model accepts various language codes.""" |
| 559 | + test_cases = [ |
| 560 | + "en-US", |
| 561 | + "es-ES", |
| 562 | + "fr-FR", |
| 563 | + "de-DE", |
| 564 | + "ja-JP", |
| 565 | + "zh-CN", |
| 566 | + "pt-BR" |
| 567 | + ] |
| 568 | + |
| 569 | + for lang_code in test_cases: |
| 570 | + transcription = Transcription(primaryLanguageCode=lang_code) |
| 571 | + assert transcription.primaryLanguageCode == lang_code |
| 572 | + |
| 573 | + |
| 574 | +def test_transcription_model_with_various_urls(): |
| 575 | + """Test that the Transcription model accepts various URL formats.""" |
| 576 | + test_urls = [ |
| 577 | + "https://example.com/transcription.json", |
| 578 | + "https://storage.googleapis.com/bucket/file.json", |
| 579 | + "https://s3.amazonaws.com/bucket/transcription.txt", |
| 580 | + "http://example.org/path/to/transcription", |
| 581 | + "https://vonage.example.com/transcriptions/12345" |
| 582 | + ] |
| 583 | + |
| 584 | + for url in test_urls: |
| 585 | + transcription = Transcription(url=url) |
| 586 | + assert transcription.url == url |
| 587 | + |
| 588 | + |
| 589 | +def test_transcription_model_boolean_has_summary(): |
| 590 | + """Test that hasSummary properly handles boolean values.""" |
| 591 | + # Test True |
| 592 | + transcription_true = Transcription(hasSummary=True) |
| 593 | + assert transcription_true.hasSummary is True |
| 594 | + |
| 595 | + # Test False |
| 596 | + transcription_false = Transcription(hasSummary=False) |
| 597 | + assert transcription_false.hasSummary is False |
| 598 | + |
| 599 | + # Test None (default) |
| 600 | + transcription_none = Transcription() |
| 601 | + assert transcription_none.hasSummary is None |
| 602 | + |
| 603 | + |
| 604 | +@responses.activate |
| 605 | +def test_archive_with_transcription_options(): |
| 606 | + """Test that Archive model properly deserializes with transcription containing new options.""" |
| 607 | + build_response( |
| 608 | + path, |
| 609 | + 'GET', |
| 610 | + 'https://video.api.vonage.com/v2/project/test_application_id/archive/5b1521e6-115f-4efd-bed9-e527b87f0699', |
| 611 | + 'archive_with_transcription.json', |
| 612 | + ) |
| 613 | + |
| 614 | + archive = video.get_archive('5b1521e6-115f-4efd-bed9-e527b87f0699') |
| 615 | + |
| 616 | + assert archive.id == '5b1521e6-115f-4efd-bed9-e527b87f0699' |
| 617 | + assert archive.has_transcription is True |
| 618 | + |
| 619 | + # Test transcription object and its new properties |
| 620 | + assert archive.transcription is not None |
| 621 | + assert archive.transcription.status == "completed" |
| 622 | + assert archive.transcription.reason == "transcription completed successfully" |
| 623 | + assert archive.transcription.url == "https://example.com/transcription.json" |
| 624 | + assert archive.transcription.primaryLanguageCode == "en-US" |
| 625 | + assert archive.transcription.hasSummary is True |
| 626 | + |
| 627 | + |
| 628 | +@responses.activate |
| 629 | +def test_list_archives_with_transcription_options(): |
| 630 | + """Test that listing archives properly handles transcription with new options.""" |
| 631 | + # Create a modified list response that includes transcription data |
| 632 | + build_response( |
| 633 | + path, |
| 634 | + 'GET', |
| 635 | + 'https://video.api.vonage.com/v2/project/test_application_id/archive', |
| 636 | + 'list_archives_with_transcription.json', |
| 637 | + ) |
| 638 | + |
| 639 | + filter = ListArchivesFilter(session_id='test_session_id') |
| 640 | + archives, count, next_page = video.list_archives(filter) |
| 641 | + |
| 642 | + # Find the archive with transcription |
| 643 | + transcribed_archive = None |
| 644 | + for archive in archives: |
| 645 | + if archive.has_transcription: |
| 646 | + transcribed_archive = archive |
| 647 | + break |
| 648 | + |
| 649 | + assert transcribed_archive is not None |
| 650 | + assert transcribed_archive.transcription is not None |
| 651 | + assert transcribed_archive.transcription.url is not None |
| 652 | + assert transcribed_archive.transcription.primaryLanguageCode is not None |
| 653 | + assert transcribed_archive.transcription.hasSummary is not None |
0 commit comments