Example #1
0
def test_field_from_unicode():
    """ """
    with open(str(FHIR_EXAMPLE_RESOURCES / "Organization.json"), "r") as fp:
        json_str = fp.read()

    fhir_field = FhirField(
        title="Organization resource",
        resource_class="tests.fixtures.MyOrganizationResource",
        fhir_release="R4",
    )

    try:
        fhir_field.from_unicode(json_str)
    except Invalid as exc:
        raise AssertionError("Code should not come here! as should return "
                             f"valid FhirResourceValue.\n{exc!s}")

    # Test with invalid json string
    try:
        invalid_data = "{hekk: invalg, 2:3}"
        fhir_field.from_unicode(invalid_data)
        raise AssertionError(
            "Code should not come here! invalid json string is provided")
    except Invalid as exc:
        assert "Invalid JSON String" in str(exc)
Example #2
0
def test_field_from_unicode_with_empty_str():
    """ """
    fhir_field = FhirField(
        title="Organization resource",
        resource_class="fhir.resources.organization.Organization",
        required=False,
        fhir_release="R4",
    )

    value = fhir_field.from_unicode("")
    assert value is None