From 17b8b6da8dd13c3adecb9d430b30f3d59456e6ef Mon Sep 17 00:00:00 2001 From: mferrera Date: Thu, 6 Mar 2025 09:49:58 +0100 Subject: [PATCH] FIX: Use dev schema in Komodo bleeding --- src/fmu/dataio/_models/_schema_base.py | 11 +++++-- tests/test_schema/test_schemas_up_to_date.py | 30 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/fmu/dataio/_models/_schema_base.py b/src/fmu/dataio/_models/_schema_base.py index bd4df1addb..1c147f6f2e 100644 --- a/src/fmu/dataio/_models/_schema_base.py +++ b/src/fmu/dataio/_models/_schema_base.py @@ -163,9 +163,14 @@ def prod_url(cls) -> str: @classmethod def url(cls) -> str: - """Returns the URL this file will reside at, based upon class variables set here - and in FmuSchemas.""" - if os.environ.get("DEV_SCHEMA", False): + """Returns the URL the schema resides at. + + Schema URLs are composed from class variables set by children derived from this + base class. If we're in a development environment, or Komodo bleeding, return + the dev schema URL.""" + if os.environ.get("DEV_SCHEMA", False) or "bleeding" in os.environ.get( + "KOMODO_RELEASE", os.environ.get("KOMODO_RELEASE_BACKUP", "") + ): return cls.dev_url() return cls.prod_url() diff --git a/tests/test_schema/test_schemas_up_to_date.py b/tests/test_schema/test_schemas_up_to_date.py index e88877e187..9cf17643e2 100644 --- a/tests/test_schema/test_schemas_up_to_date.py +++ b/tests/test_schema/test_schemas_up_to_date.py @@ -63,6 +63,36 @@ def test_schema_url_changes_with_env_var( assert json["$schema"] == "https://json-schema.org/draft/2020-12/schema" +@pytest.mark.parametrize("schema", schemas) +@pytest.mark.parametrize("env_var", ["KOMODO_RELEASE", "KOMODO_RELEASE_BACKUP"]) +@pytest.mark.parametrize( + "env_var_value", + [ + "bleeding", + "kenv_bleeding", + "bleeding-20250306-0207-py311-rhel8", + ], +) +def test_schema_url_changes_with_komodo_bleeding_env_var( + schema: SchemaBase, env_var: str, env_var_value: str, monkeypatch: MonkeyPatch +) -> None: + """Tests that the schema uses the development url when KOMODO_RELEASE or + KOMODO_RELEASE_BACKUP is set to a bleeding release. + + DEV_SCHEMA is set to 1 whenever the tests are run, so it is unset here.""" + monkeypatch.delenv("DEV_SCHEMA", raising=False) + json = schema.dump() + assert schema.url().startswith(FmuSchemas.PROD_URL) + assert json["$id"].startswith(FmuSchemas.PROD_URL) + assert json["$schema"] == "https://json-schema.org/draft/2020-12/schema" + + monkeypatch.setenv(env_var, env_var_value) + json = schema.dump() + assert schema.url().startswith(FmuSchemas.DEV_URL) + assert json["$id"].startswith(FmuSchemas.DEV_URL) + assert json["$schema"] == "https://json-schema.org/draft/2020-12/schema" + + @pytest.mark.parametrize("schema", schemas) def test_no_discriminator_mappings_leftover_in_schema(schema: SchemaBase) -> None: """Sumo's AJV validator doesn't like discriminator mappings leftover in the