from datetime import datetime, timedelta import pytest pytestmark = pytest.mark.nft try: from app.core.models.license.nft_license import NFTLicense except Exception: NFTLicense = None # type: ignore @pytest.mark.skipif(NFTLicense is None, reason="NFTLicense model not importable") def test_nft_license_active_by_default(): lic = NFTLicense( license_id="LIC-1", content_id="CID-1", owner_address="EQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", nft_address="EQyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", ) assert lic.is_active(), "License without expires_at must be active" @pytest.mark.skipif(NFTLicense is None, reason="NFTLicense model not importable") def test_nft_license_expired_detection(): past = datetime.utcnow() - timedelta(days=1) lic = NFTLicense( license_id="LIC-2", content_id="CID-2", owner_address="EQowner", nft_address="EQnft", expires_at=past, ) assert not lic.is_active(), "Expired license must not be active" @pytest.mark.skipif(NFTLicense is None, reason="NFTLicense model not importable") def test_nft_license_to_from_dict_roundtrip(): future = datetime.utcnow() + timedelta(days=7) lic = NFTLicense( license_id="LIC-3", content_id="CID-3", owner_address="EQo", nft_address="EQn", expires_at=future, ) d = lic.to_dict() restored = NFTLicense.from_dict(d) assert restored.license_id == lic.license_id assert restored.content_id == lic.content_id assert restored.owner_address == lic.owner_address assert restored.nft_address == lic.nft_address assert (restored.expires_at is not None) and abs((restored.expires_at - future).total_seconds()) < 2