- Timestamp:
- 11/02/25 18:49:14 (2 months ago)
- Branches:
- master
- Children:
- bf30018
- Parents:
- 8aa20c7
- Location:
- tests
- Files:
-
- 3 edited
-
conftest.py (modified) (5 diffs)
-
test_id_lifecycle.py (modified) (4 diffs)
-
test_id_stress.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tests/conftest.py
r8aa20c7 r5c72356 4 4 from dataclasses import dataclass, field 5 5 from typing import List 6 from flexoentity import Flex oEntity, EntityType, EntityState, Domain6 from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState, Domain 7 7 8 8 @pytest.fixture … … 37 37 class SingleChoiceQuestion(FlexoEntity): 38 38 """A minimal stub to test FlexoEntity integration.""" 39 ENTITY_TYPE = EntityType.ITEM 40 39 41 text: str = "" 40 42 options: List[AnswerOption] = field(default_factory=list) 41 43 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 ) 42 57 43 58 @classmethod 44 59 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")) 49 61 50 62 def to_dict(self): … … 68 80 @classmethod 69 81 def from_dict(cls, data): 70 obj = cls( 82 obj = cls(domain=Domain(domain="GEN"), 71 83 text=data.get("text", ""), 72 84 options=[AnswerOption.from_dict(o) for o in data.get("options", [])], … … 74 86 # restore FlexoEntity core fields 75 87 obj.domain = data.get("domain") 76 obj.entity_type = EntityType[data.get("etype")] if "etype" in data else EntityType.ITEM77 obj.state = EntityState[data.get("state")] if "state" in data else EntityState.DRAFT78 88 if "flexo_id" in data: 79 from flexoentity import FlexOID80 89 obj.flexo_id = FlexOID.parsed(data["flexo_id"]) 81 90 return obj … … 87 96 @pytest.fixture 88 97 def sample_question(): 89 returnSingleChoiceQuestion(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 -
tests/test_id_lifecycle.py
r8aa20c7 r5c72356 20 20 assert q.flexo_id.version == 1 21 21 22 23 def test_signing_bumps_version(sample_question): 22 def test_signing_does_not_bump_version(sample_question): 24 23 q = sample_question 25 24 q.approve() 26 v_before = str(q.flexo_id)25 before = q.flexo_id 27 26 q.sign() 27 after = q.flexo_id 28 29 # state changed 28 30 assert q.state == EntityState.APPROVED_AND_SIGNED 29 assert str(q.flexo_id) != v_before 31 32 # version unchanged 33 assert before.version == after.version 34 35 # only suffix letter differs 36 assert before.prefix == after.prefix 37 assert before.state_code == "A" 38 assert after.state_code == "S" 30 39 31 40 32 def test_publish_ bumps_version(sample_question):41 def test_publish_does_not_bump_version(sample_question): 33 42 q = sample_question 34 43 q.approve() … … 37 46 q.publish() 38 47 assert q.state == EntityState.PUBLISHED 39 assert q.flexo_id.version == v_before + 148 assert q.flexo_id.version == v_before 40 49 41 50 … … 70 79 # simulate tampering 71 80 q.text = "Tampered text" 81 print(FlexoEntity.debug_integrity(q)) 72 82 assert not FlexoEntity.verify_integrity(q) 73 83 … … 112 122 for _ in range(FlexOID.MAX_VERSION - 1): 113 123 q.bump_version() 124 125 # Next one must raise 114 126 with pytest.raises(RuntimeError, match="mark obsolete"): 115 q. sign()127 q.bump_version() -
tests/test_id_stress.py
r8aa20c7 r5c72356 82 82 83 83 84 def test_version_ceiling_enforcement(sample_question):85 """Simulate approaching @999 to trigger obsolescence guard."""86 q = sample_question87 q.approve()88 89 # artificially bump version number to near ceiling90 q.flexo_id = FlexOID.from_oid_and_version(q.flexo_id, 998)91 92 # 998 → 999 is allowed93 q.sign()94 assert q.flexo_id.version == 99995 96 # 999 → 1000 should raise RuntimeError97 with pytest.raises(ValueError):98 q.publish()99 100 101 84 def test_massive_lifecycle_simulation(sample_question): 102 85 """
Note:
See TracChangeset
for help on using the changeset viewer.
