import textwrap import pytest from apim_apps import load_manifest, ApiAccess MINIMAL = textwrap.dedent("""\ organizations: [] applications: [] """) FULL = textwrap.dedent("""\ organizations: - name: "MyOrg" description: "Test org" email: "org@example.com" enabled: true development: false environments: - DEV_LAN applications: - name: "MyApp" organization: "MyOrg" description: "Test app" email: "app@example.com" enabled: true environments: - DEV_LAN apis: - name: "MyAPI" version: "v1" - "OtherAPI" """) NO_ENVS = textwrap.dedent("""\ organizations: - name: "GlobalOrg" applications: - name: "GlobalApp" organization: "GlobalOrg" """) def test_minimal(tmp_path): f = tmp_path / "apps.yaml" f.write_text(MINIMAL) m = load_manifest(str(f)) assert m.organizations == [] assert m.applications == [] def test_full_org_fields(tmp_path): f = tmp_path / "apps.yaml" f.write_text(FULL) m = load_manifest(str(f)) assert len(m.organizations) == 1 org = m.organizations[0] assert org.name == "MyOrg" assert org.description == "Test org" assert org.email == "org@example.com" assert org.enabled is True assert org.development is False assert org.environments == ["DEV_LAN"] def test_full_app_fields(tmp_path): f = tmp_path / "apps.yaml" f.write_text(FULL) m = load_manifest(str(f)) assert len(m.applications) == 1 app = m.applications[0] assert app.name == "MyApp" assert app.org_name == "MyOrg" assert app.environments == ["DEV_LAN"] def test_api_access_named(tmp_path): f = tmp_path / "apps.yaml" f.write_text(FULL) m = load_manifest(str(f)) apis = m.applications[0].apis assert len(apis) == 2 assert apis[0] == ApiAccess(api_name="MyAPI", api_version="v1") assert apis[1] == ApiAccess(api_name="OtherAPI", api_version="") def test_defaults_when_envs_omitted(tmp_path): f = tmp_path / "apps.yaml" f.write_text(NO_ENVS) m = load_manifest(str(f)) assert m.organizations[0].environments == [] assert m.applications[0].environments == [] assert m.applications[0].apis == []