Changeset 5c72356 in flexoentity for tests/conftest.py


Ignore:
Timestamp:
11/02/25 18:49:14 (2 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
master
Children:
bf30018
Parents:
8aa20c7
Message:

fix tests due to simplifying state and type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/conftest.py

    r8aa20c7 r5c72356  
    44from dataclasses import dataclass, field
    55from typing import List
    6 from flexoentity import FlexoEntity, EntityType, EntityState, Domain
     6from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState, Domain
    77
    88@pytest.fixture
     
    3737class SingleChoiceQuestion(FlexoEntity):
    3838    """A minimal stub to test FlexoEntity integration."""
     39    ENTITY_TYPE = EntityType.ITEM
     40
    3941    text: str = ""
    4042    options: List[AnswerOption] = field(default_factory=list)
    4143
     44    def __post_init__(self):
     45        # If no FlexOID yet, generate a draft ID now.
     46        if not getattr(self, "flexo_id", None):
     47            domain_code = (
     48                self.domain.domain if isinstance(self.domain, Domain) else "GEN"
     49            )
     50            self.flexo_id = FlexOID.safe_generate(
     51                domain=domain_code,
     52                entity_type=EntityType.ITEM.value,     # 'I'
     53                estate=EntityState.DRAFT.value,        # 'D'
     54                text=self.text_seed or self.text,
     55                version=1,
     56            )
    4257
    4358    @classmethod
    4459    def default(cls):
    45         return cls(domain=Domain(domain="GEN",
    46                                  entity_type=EntityType.DOMAIN,
    47                                  state=EntityState.DRAFT),
    48                    state=EntityState.DRAFT, entity_type=EntityType.ITEM)
     60        return cls(domain=Domain(domain="GEN"))
    4961
    5062    def to_dict(self):
     
    6880    @classmethod
    6981    def from_dict(cls, data):
    70         obj = cls(
     82        obj = cls(domain=Domain(domain="GEN"),
    7183            text=data.get("text", ""),
    7284            options=[AnswerOption.from_dict(o) for o in data.get("options", [])],
     
    7486        # restore FlexoEntity core fields
    7587        obj.domain = data.get("domain")
    76         obj.entity_type = EntityType[data.get("etype")] if "etype" in data else EntityType.ITEM
    77         obj.state = EntityState[data.get("state")] if "state" in data else EntityState.DRAFT
    7888        if "flexo_id" in data:
    79             from flexoentity import FlexOID
    8089            obj.flexo_id = FlexOID.parsed(data["flexo_id"])
    8190        return obj
     
    8796@pytest.fixture
    8897def sample_question():
    89     return SingleChoiceQuestion(domain=Domain.default(),
    90                                text="What is 2 + 2?",
    91                                options=[],
    92                                entity_type=EntityType.ITEM,
    93                                state=EntityState.DRAFT)
     98    q = SingleChoiceQuestion(domain=Domain.default(),
     99                             text="What is 2 + 2?",
     100                             options=[])
     101    q._update_fingerprint()
     102    return q
Note: See TracChangeset for help on using the changeset viewer.