Changeset 02d288d in flexoentity for tests/conftest.py
- Timestamp:
- 10/23/25 13:27:08 (3 months ago)
- Branches:
- master
- Children:
- 4ceca57
- Parents:
- 6a7dec1
- File:
-
- 1 edited
-
tests/conftest.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tests/conftest.py
r6a7dec1 r02d288d 5 5 from flexoentity import FlexoEntity, EntityType, EntityState, Domain 6 6 7 import pytest 8 import json 9 from flexoentity import EntityType, EntityState, Domain 10 from builder.questions import RadioQuestion, AnswerOption # adjust path if different 11 from builder.media_items import NullMediaItem # adjust import if needed 7 12 8 class DummyEntity(FlexoEntity):9 """Minimal concrete subclass for testing FlexoEntity logic."""10 13 11 def __init__(self, domain, etype, state, seed="DUMMY"): 12 self._seed = seed 13 super().__init__(domain, etype, state) 14 @pytest.fixture(scope="session") 15 def 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 ) 14 26 15 @property16 def text_seed(self) -> str:17 return self._seed18 27 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 29 def 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 27 43 28 @classmethod 29 def from_json(cls, data_str: str): 30 return cls.from_dict(json.loads(data_str)) 31 44 32 45 @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 ) 46 def serialized_question(radio_question): 47 """Provide the serialized JSON form for roundtrip tests.""" 48 return radio_question.to_json() 49 50 51 @pytest.fixture 52 def deserialized_question(serialized_question): 53 """Recreate a question from JSON for consistency tests.""" 54 return RadioQuestion.from_json(serialized_question) 55 40 56 41 57 @pytest.fixture 42 58 def null_media(): 43 """Provide a default NullMediaItem instance for tests."""59 """Provide a default NullMediaItem instance for media tests.""" 44 60 return NullMediaItem( 45 domain= "GEN",61 domain=domain, 46 62 etype=EntityType.MEDIA, 47 63 state=EntityState.DRAFT
Note:
See TracChangeset
for help on using the changeset viewer.
