Beispiel #1
0
def test_require_either_oas_url_or_file():
    oas_path = os.path.join(os.path.dirname(__file__), "schemas/drc.yaml")
    with open(oas_path, "r") as oas_file:
        service = Service(
            label="Test",
            api_type=APITypes.drc,
            api_root="http://foo.bar",
            # oas and oas_file both empty
            oas="",
            oas_file=None,
        )
        service.save()

    with pytest.raises(ValidationError) as excinfo:
        service.full_clean()

    # check both fields have a message
    error = excinfo.value.error_dict
    assert error["oas"][0].messages == ["Set either oas or oas_file"]
    assert error["oas_file"][0].messages == ["Set either oas or oas_file"]
Beispiel #2
0
def test_require_exclusively_oas_url_or_file(settings, tmp_path):
    settings.MEDIA_ROOT = tmp_path
    oas_path = os.path.join(os.path.dirname(__file__), "schemas/drc.yaml")

    with open(oas_path, "r") as oas_file:
        service = Service(
            label="Test",
            api_type=APITypes.drc,
            api_root="http://foo.bar",
            # oas and oas_file both defined
            oas="http://foo.bar/schema.yaml",
            oas_file=File(oas_file, name="schema.yaml"),
        )
        service.save()

    with pytest.raises(ValidationError) as excinfo:
        service.full_clean()

    # check both fields have a message
    error = excinfo.value.error_dict
    assert error["oas"][0].messages == ["Set either oas or oas_file, not both"]
    assert error["oas_file"][0].messages == [
        "Set either oas or oas_file, not both"
    ]