Commit e7f1ec95 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

Add tests

parent 7af630f2
Loading
Loading
Loading
Loading

tests/test_domain.py

0 → 100644
+58 −0
Original line number Diff line number Diff line
from datetime import datetime, timezone
from uuid import uuid4

from federation_manager.domain.models import Agreement, PartnerOP


def _dt(y: int, m: int, d: int) -> datetime:
    return datetime(y, m, d, tzinfo=timezone.utc)


def _agreement(**over: object) -> Agreement:
    zone = uuid4()
    base: dict[str, object] = {
        "id": uuid4(),
        "partner_op_id": uuid4(),
        "permitted_api_types": {"edge-cloud-deploy"},
        "permitted_zone_ids": {zone},
        "service_spec_mappings": {"partner-app": uuid4()},
        "valid_from": _dt(2026, 1, 1),
        "valid_until": _dt(2027, 1, 1),
        "status": "active",
    }
    base.update(over)
    return Agreement(**base)  # type: ignore[arg-type]


def test_partner_is_active() -> None:
    assert PartnerOP(uuid4(), "214-07", "active").is_active()
    assert not PartnerOP(uuid4(), "214-07", "suspended").is_active()


def test_valid_at_boundaries() -> None:
    a = _agreement()
    assert not a.is_valid_at(_dt(2025, 12, 31))  # before valid_from
    assert a.is_valid_at(_dt(2026, 6, 1))  # inside
    assert not a.is_valid_at(_dt(2027, 1, 1))  # valid_until is exclusive
    assert not a.is_valid_at(_dt(2027, 6, 1))  # after


def test_valid_until_none_is_indefinite() -> None:
    a = _agreement(valid_until=None)
    assert a.is_valid_at(_dt(2099, 1, 1))


def test_permits_api_and_zone() -> None:
    zone = uuid4()
    a = _agreement(permitted_api_types={"edge-cloud-deploy"}, permitted_zone_ids={zone})
    assert a.permits_api("edge-cloud-deploy")
    assert not a.permits_api("edge-cloud-terminate")
    assert a.permits_zone(zone)
    assert not a.permits_zone(uuid4())


def test_resolve_spec_id() -> None:
    spec = uuid4()
    a = _agreement(service_spec_mappings={"partner-app": spec})
    assert a.resolve_spec_id("partner-app") == spec
    assert a.resolve_spec_id("unknown-app") is None