Skip to content

Commit

Permalink
FIX: Use dev schema in Komodo bleeding
Browse files Browse the repository at this point in the history
  • Loading branch information
mferrera committed Mar 6, 2025
1 parent f073d3c commit 5f01522
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/fmu/dataio/_models/_schema_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. In we're in a development environment, or Komodo bleeding, return
the dev environment 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()

Expand Down
30 changes: 30 additions & 0 deletions tests/test_schema/test_schemas_up_to_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 production url when KOMODO_RELEASE 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
Expand Down

0 comments on commit 5f01522

Please sign in to comment.