Changeset 02d288d in flexoentity for tests/conftest.py


Ignore:
Timestamp:
10/23/25 13:27:08 (3 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
master
Children:
4ceca57
Parents:
6a7dec1
Message:

improve hash generation and collision handler - move signature from FlexOID to FlexoEntity

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/conftest.py

    r6a7dec1 r02d288d  
    55from flexoentity import FlexoEntity, EntityType, EntityState, Domain
    66
     7import pytest
     8import json
     9from flexoentity import EntityType, EntityState, Domain
     10from builder.questions import RadioQuestion, AnswerOption  # adjust path if different
     11from builder.media_items import NullMediaItem  # adjust import if needed
    712
    8 class DummyEntity(FlexoEntity):
    9     """Minimal concrete subclass for testing FlexoEntity logic."""
    1013
    11     def __init__(self, domain, etype, state, seed="DUMMY"):
    12         self._seed = seed
    13         super().__init__(domain, etype, state)
     14@pytest.fixture(scope="session")
     15def domain():
     16    """Provide a reusable domain for all entity tests."""
     17    return Domain(
     18        domain="SIG",
     19        etype=EntityType.DOMAIN,
     20        state=EntityState.DRAFT,
     21        fullname="Signal Corps",
     22        description="Questions related to communications and signaling systems.",
     23        classification="RESTRICTED",
     24        owner="test-suite"
     25    )
    1426
    15     @property
    16     def text_seed(self) -> str:
    17         return self._seed
    1827
    19     @classmethod
    20     def from_dict(cls, data):
    21         """Ensure enums and seed are reconstructed correctly."""
    22         domain = data["domain"]
    23         etype = EntityType[data["etype"]] if isinstance(data["etype"], str) else data["etype"]
    24         state = EntityState[data["state"]] if isinstance(data["state"], str) else data["state"]
    25         seed = data.get("text_seed", "DUMMY-CONTENT")
    26         return cls(domain=domain, etype=etype, state=state, seed=seed)
     28@pytest.fixture
     29def radio_question(domain):
     30    """Return a simple RadioQuestion entity for testing FlexoEntity logic."""
     31    q = RadioQuestion(
     32        domain=domain,
     33        etype=EntityType.QUESTION,
     34        state=EntityState.DRAFT,
     35        text="Which frequency band is used for shortwave communication?",
     36        options=[
     37            AnswerOption(id="opt1", text="HF (3–30 MHz)", points=1),
     38            AnswerOption(id="opt2", text="VHF (30–300 MHz)", points=0),
     39            AnswerOption(id="opt3", text="UHF (300–3000 MHz)", points=0),
     40        ]
     41    )
     42    return q
    2743
    28     @classmethod
    29     def from_json(cls, data_str: str):
    30         return cls.from_dict(json.loads(data_str))
    31    
     44
    3245@pytest.fixture
    33 def entity():
    34     """Generic FlexoEntity-like instance in draft state."""
    35     return DummyEntity(
    36         domain=Domain(domain="SIG", etype=EntityType.DOMAIN, state=EntityState.DRAFT, fullname="Signal Corps", classification="RESTRICTED"),
    37         etype=EntityType.CATALOG,
    38         state=EntityState.DRAFT,
    39     )
     46def serialized_question(radio_question):
     47    """Provide the serialized JSON form for roundtrip tests."""
     48    return radio_question.to_json()
     49
     50
     51@pytest.fixture
     52def deserialized_question(serialized_question):
     53    """Recreate a question from JSON for consistency tests."""
     54    return RadioQuestion.from_json(serialized_question)
     55
    4056
    4157@pytest.fixture
    4258def null_media():
    43     """Provide a default NullMediaItem instance for tests."""
     59    """Provide a default NullMediaItem instance for media tests."""
    4460    return NullMediaItem(
    45         domain="GEN",
     61        domain=domain,
    4662        etype=EntityType.MEDIA,
    4763        state=EntityState.DRAFT
Note: See TracChangeset for help on using the changeset viewer.