Changeset 9592936 in flexoentity


Ignore:
Timestamp:
11/20/25 13:10:31 (8 weeks ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
master
Children:
b24d72e
Parents:
fd1913f
Message:

adopt tests to reflect new design of Entity creation

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • flexoentity/domain.py

    rfd1913f r9592936  
    4949            classification=data.get("classification", "UNCLASSIFIED"),
    5050            flexo_id=flexo_id,
     51            _in_factory=True
    5152        )
    5253
  • flexoentity/domain_manager.py

    rfd1913f r9592936  
    7373                                         entity_type=EntityType.DOMAIN.value,
    7474                                         state=EntityState.DRAFT.value, text=domain_id)
    75         domain = Domain(flexo_id=flexo_id, **kwargs)
     75        domain = Domain(flexo_id=flexo_id, _in_factory=True, **kwargs)
    7676        return cls.register(domain)
    7777
  • flexoentity/flexo_entity.py

    rfd1913f r9592936  
    155155    I am the living, editable layer that connects identity with accountability.
    156156    """
     157    _in_factory: bool = field(default=False, repr=False)
    157158    subtype: str = "GENERIC"
    158159    flexo_id: Optional[FlexOID] = field(default=None)
     
    161162    owner_id: UUID = field(default=UUID(int=0))
    162163    origin: Optional[str] = field(default=None)
    163    
     164
    164165    def with_new_owner(self, new_owner: UUID):
    165166        """I return a clone of this entity with a different owner."""
     
    229230        )
    230231
    231         obj = cls(flexo_id=flexo_id, **kwargs)
     232        obj = cls(flexo_id=flexo_id, _in_factory=True, **kwargs)
    232233        obj.fingerprint = obj._compute_fingerprint()
    233234        return obj
     
    240241            - Domain must always match flexo_id.domain.
    241242        """
    242 
     243        if not self._in_factory:
     244            raise RuntimeError(
     245                f"{self.__class__.__name__} must be created via with_domain_id() "
     246                f"or from_dict(), not via direct construction."
     247            )
    243248        # Step 1: If flexo_id exists, restore canonical domain
    244249        if self.flexo_id:
     
    252257            raise ValueError(
    253258                f"{self.__class__.__name__} created without domain; "
    254                 f"use {self.__class__.__name__}.with_domain(domain=...) or pass domain explicitly."
     259                f"use {self.__class__.__name__}.with_domain_id(domain=...) or pass domain explicitly."
    255260            )
    256261
  • tests/conftest.py

    rfd1913f r9592936  
    44from dataclasses import dataclass, field
    55from typing import List
    6 from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState, Domain
     6from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState, Domain, DomainManager
    77
    88@pytest.fixture
     
    1515    return FixedDate
    1616
     17@pytest.fixture(autouse=True)
     18def reset_domain_manager():
     19    DomainManager.clear()   # You need to implement this
     20    yield
     21    DomainManager.clear()
     22
     23@pytest.fixture(autouse=True)
     24def auto_domains():
     25    Domain.with_domain_id("GENERAL", fullname="General Domain")
     26    Domain.with_domain_id("TEST", fullname="Test Domain")
    1727
    1828@dataclass
     
    4656        if not getattr(self, "flexo_id", None):
    4757            self.flexo_id = FlexOID.safe_generate(
    48                 domain=self.domain_id,
     58                domain_id=self.domain_id,
    4959                entity_type=SingleChoiceQuestion.ENTITY_TYPE.value,     # 'I'
    50                 estate=EntityState.DRAFT.value,        # 'D'
     60                state=EntityState.DRAFT.value,        # 'D'
    5161                text=self.text_seed or self.text,
    5262                version=1,
     
    8898def sample_domain():
    8999    domain_id = "PY_ARITHM"
    90     flexo_id = FlexOID.safe_generate(domain_id=domain_id,
    91                                      entity_type=EntityType.DOMAIN.value,
    92                                      state=EntityState.DRAFT.value, text=domain_id)
    93     return Domain(flexo_id=flexo_id, fullname="PYTHON_ARITHMETIC",
    94                   description="ALL ABOUT ARITHMETIC IN PYTHON")
     100    return Domain.with_domain_id(domain_id=domain_id,
     101                                 fullname="PYTHON_ARITHMETIC",
     102                                 description="ALL ABOUT ARITHMETIC IN PYTHON")
    95103
    96104@pytest.fixture
    97105def sample_question(sample_domain):
    98     flexo_id = FlexOID.safe_generate(domain_id=sample_domain.domain_id,
    99                                      entity_type=EntityType.ITEM.value,
    100                                      state=EntityState.DRAFT.value,
    101                                      text="What is 2 + 2")
    102     q = SingleChoiceQuestion(flexo_id=flexo_id, text="What is 2 + 2?",
    103                              options=[])
     106    q = SingleChoiceQuestion.with_domain_id(domain_id=sample_domain.domain_id,
     107                                            text="What is 2 + 2?",
     108                                            options=[])
    104109    q._update_fingerprint()
    105110    return q
Note: See TracChangeset for help on using the changeset viewer.