|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
5 | | -from nrlf.core.constants import PointerTypes |
| 5 | +from nrlf.core.constants import ODS_SYSTEM, PointerTypes |
6 | 6 | from nrlf.core.errors import ParseError |
7 | 7 | from nrlf.core.validators import ( |
8 | 8 | DocumentReferenceValidator, |
@@ -640,6 +640,140 @@ def test_validate_content_extension_too_many_extensions(): |
640 | 640 | } |
641 | 641 |
|
642 | 642 |
|
| 643 | +def test_validate_author_too_many_authors(): |
| 644 | + validator = DocumentReferenceValidator() |
| 645 | + document_ref_data = load_document_reference_json("Y05868-736253002-Valid") |
| 646 | + |
| 647 | + document_ref_data["author"].append( |
| 648 | + { |
| 649 | + "identifier": { |
| 650 | + "system": ODS_SYSTEM, |
| 651 | + "value": "someODSCode", |
| 652 | + } |
| 653 | + } |
| 654 | + ) |
| 655 | + |
| 656 | + result = validator.validate(document_ref_data) |
| 657 | + |
| 658 | + assert result.is_valid is False |
| 659 | + assert result.resource.id == "Y05868-99999-99999-999999" |
| 660 | + assert len(result.issues) == 1 |
| 661 | + assert result.issues[0].model_dump(exclude_none=True) == { |
| 662 | + "severity": "error", |
| 663 | + "code": "invalid", |
| 664 | + "details": { |
| 665 | + "coding": [ |
| 666 | + { |
| 667 | + "system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1", |
| 668 | + "code": "INVALID_RESOURCE", |
| 669 | + "display": "Invalid validation of resource", |
| 670 | + } |
| 671 | + ] |
| 672 | + }, |
| 673 | + "diagnostics": "Invalid author length: 2 Author must only contain a single value", |
| 674 | + "expression": ["author"], |
| 675 | + } |
| 676 | + |
| 677 | + |
| 678 | +def test_validate_author_system_invalid(): |
| 679 | + validator = DocumentReferenceValidator() |
| 680 | + document_ref_data = load_document_reference_json("Y05868-736253002-Valid") |
| 681 | + |
| 682 | + document_ref_data["author"][0] = { |
| 683 | + "identifier": { |
| 684 | + "system": "some system", |
| 685 | + "value": "someODSCode", |
| 686 | + } |
| 687 | + } |
| 688 | + |
| 689 | + result = validator.validate(document_ref_data) |
| 690 | + |
| 691 | + assert result.is_valid is False |
| 692 | + assert result.resource.id == "Y05868-99999-99999-999999" |
| 693 | + assert len(result.issues) == 1 |
| 694 | + assert result.issues[0].model_dump(exclude_none=True) == { |
| 695 | + "severity": "error", |
| 696 | + "code": "invalid", |
| 697 | + "details": { |
| 698 | + "coding": [ |
| 699 | + { |
| 700 | + "system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1", |
| 701 | + "code": "INVALID_IDENTIFIER_SYSTEM", |
| 702 | + "display": "Invalid identifier system", |
| 703 | + } |
| 704 | + ] |
| 705 | + }, |
| 706 | + "diagnostics": f"Invalid author system: 'some system' Author system must be 'https://fhir.nhs.uk/Id/ods-organization-code'", |
| 707 | + "expression": ["author[0].identifier.system"], |
| 708 | + } |
| 709 | + |
| 710 | + |
| 711 | +def test_validate_author_value_invalid(): |
| 712 | + validator = DocumentReferenceValidator() |
| 713 | + document_ref_data = load_document_reference_json("Y05868-736253002-Valid") |
| 714 | + |
| 715 | + document_ref_data["author"][0] = { |
| 716 | + "identifier": { |
| 717 | + "system": ODS_SYSTEM, |
| 718 | + "value": "!!!!!!12sd", |
| 719 | + } |
| 720 | + } |
| 721 | + |
| 722 | + result = validator.validate(document_ref_data) |
| 723 | + |
| 724 | + assert result.is_valid is False |
| 725 | + assert result.resource.id == "Y05868-99999-99999-999999" |
| 726 | + assert len(result.issues) == 1 |
| 727 | + assert result.issues[0].model_dump(exclude_none=True) == { |
| 728 | + "severity": "error", |
| 729 | + "code": "value", |
| 730 | + "details": { |
| 731 | + "coding": [ |
| 732 | + { |
| 733 | + "system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1", |
| 734 | + "code": "INVALID_RESOURCE", |
| 735 | + "display": "Invalid validation of resource", |
| 736 | + } |
| 737 | + ] |
| 738 | + }, |
| 739 | + "diagnostics": f"Invalid author value: '!!!!!!12sd' Author value must be alphanumeric", |
| 740 | + "expression": ["author[0].identifier.value"], |
| 741 | + } |
| 742 | + |
| 743 | + |
| 744 | +def test_validate_author_value_too_long(): |
| 745 | + validator = DocumentReferenceValidator() |
| 746 | + document_ref_data = load_document_reference_json("Y05868-736253002-Valid") |
| 747 | + |
| 748 | + document_ref_data["author"][0] = { |
| 749 | + "identifier": { |
| 750 | + "system": ODS_SYSTEM, |
| 751 | + "value": "d1111111111111111111111111111111111111111111111", |
| 752 | + } |
| 753 | + } |
| 754 | + |
| 755 | + result = validator.validate(document_ref_data) |
| 756 | + |
| 757 | + assert result.is_valid is False |
| 758 | + assert result.resource.id == "Y05868-99999-99999-999999" |
| 759 | + assert len(result.issues) == 1 |
| 760 | + assert result.issues[0].model_dump(exclude_none=True) == { |
| 761 | + "severity": "error", |
| 762 | + "code": "value", |
| 763 | + "details": { |
| 764 | + "coding": [ |
| 765 | + { |
| 766 | + "system": "https://fhir.nhs.uk/ValueSet/Spine-ErrorOrWarningCode-1", |
| 767 | + "code": "INVALID_RESOURCE", |
| 768 | + "display": "Invalid validation of resource", |
| 769 | + } |
| 770 | + ] |
| 771 | + }, |
| 772 | + "diagnostics": f"Invalid author value: 'd1111111111111111111111111111111111111111111111' Author value must be less than 13 characters", |
| 773 | + "expression": ["author[0].identifier.value"], |
| 774 | + } |
| 775 | + |
| 776 | + |
643 | 777 | def test_validate_content_extension_invalid_code(): |
644 | 778 | validator = DocumentReferenceValidator() |
645 | 779 | document_ref_data = load_document_reference_json("Y05868-736253002-Valid") |
|
0 commit comments