Changeset 8a238e2 in flexoentity for tests/test_id_lifecycle.py
- Timestamp:
- 10/20/25 13:15:45 (3 months ago)
- Branches:
- master
- Children:
- 3d65ce5
- Parents:
- 045b864
- File:
-
- 1 edited
-
tests/test_id_lifecycle.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tests/test_id_lifecycle.py
r045b864 r8a238e2 1 import os2 import sys3 1 import pytest 4 sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))5 2 6 3 from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState 7 4 8 9 @pytest.fixture 10 def question(): 11 """Fresh question entity in draft state."""12 return FlexoEntity("AF", EntityType.QUESTION, "What is Ohm’s law?", EntityState.DRAFT)5 def test_initial_state(entity): 6 assert entity.state == EntityState.DRAFT 7 assert entity.flexo_id.version == 1 8 assert len(entity.flexo_id.signature) == 16 # blake2s digest_size=8 → 16 hex 9 assert FlexoEntity.verify_integrity(entity) 13 10 14 11 15 # ────────────────────────────────────────────────────────────────────────────── 16 def test_initial_state(question): 17 assert question.state == EntityState.DRAFT 18 assert question.flexo_id.version == 1 19 assert len(question.flexo_id.signature) == 16 # blake2s digest_size=8 → 16 hex 20 assert FlexoEntity.verify_integrity(question) 12 def test_approval_bumps_version(entity): 13 entity.approve() 14 assert entity.state == EntityState.APPROVED 15 assert entity.flexo_id.version == 2 21 16 22 17 23 def test_approval_bumps_version(question): 24 question.approve() 25 assert question.state == EntityState.APPROVED 26 assert question.flexo_id.version == 2 18 def test_signing_bumps_version(entity): 19 entity.approve() 20 v_before = entity.flexo_id 21 entity.sign() 22 assert entity.state == EntityState.APPROVED_AND_SIGNED 23 assert entity.flexo_id != v_before 27 24 28 25 29 def test_signing_bumps_version(question): 30 question.approve() 31 v_before = question.flexo_id 32 question.sign() 33 assert question.state == EntityState.APPROVED_AND_SIGNED 34 assert question.flexo_id != v_before 35 36 def test_publish_bumps_version(question): 37 question.approve() 38 question.sign() 39 v_before = question.flexo_id.version 40 question.publish() 41 assert question.state == EntityState.PUBLISHED 42 assert question.flexo_id.version == v_before + 1 43 44 def test_modify_content_changes_fingerprint(question): 45 old_signature = question.flexo_id.signature 46 question.modify_content("Rephrased Ohm’s law?") 47 assert question.flexo_id.signature != old_signature 26 def test_publish_bumps_version(entity): 27 entity.approve() 28 entity.sign() 29 v_before = entity.flexo_id.version 30 entity.publish() 31 assert entity.state == EntityState.PUBLISHED 32 assert entity.flexo_id.version == v_before + 1 48 33 49 34 50 def test_no_version_bump_on_draft_edits(question): 51 question.modify_content("Draft edit only") 52 assert question.flexo_id.version == 1 35 def test_modify_content_changes_fingerprint(entity): 36 old_signature = entity.flexo_id.signature 37 entity._seed = "Rephrased content" # simulate text change 38 entity._update_fingerprint() 39 assert entity.flexo_id.signature != old_signature 53 40 54 41 55 def test_version_bump_after_edit_and_sign(question): 56 question.approve() 57 v1 = question.flexo_id 58 question.modify_content("Changed content") 59 question.sign() 60 assert question.flexo_id != v1 42 def test_no_version_bump_on_draft_edits(entity): 43 entity._seed = "Draft edit only" 44 entity._update_fingerprint() 45 assert entity.flexo_id.version == 1 61 46 62 47 63 def test_ integrity_check_passes_and_fails(question):64 question.approve()65 assert FlexoEntity.verify_integrity(question)66 # simulate tampering67 question.text_seed = "Tampered text"68 assert not FlexoEntity.verify_integrity(question)48 def test_version_bump_after_edit_and_sign(entity): 49 entity.approve() 50 v1 = entity.flexo_id 51 entity._seed = "Changed content" 52 entity.sign() 53 assert entity.flexo_id != v1 69 54 70 55 71 def test_ obsolete_state(question):72 question.approve()73 question.sign()74 question.publish()75 question.obsolete()76 assert question.state == EntityState.OBSOLETE56 def test_integrity_check_passes_and_fails(entity): 57 entity.approve() 58 assert FlexoEntity.verify_integrity(entity) 59 # simulate tampering 60 entity._seed = "Tampered text" 61 assert not FlexoEntity.verify_integrity(entity) 77 62 78 63 79 def test_clone_new_base_resets_lineage(question): 80 question.approve() 81 question.sign() 82 question.publish() 83 question.obsolete() 84 old_id = question.flexo_id 85 question.clone_new_base() 86 assert question.flexo_id != old_id 87 assert question.state == EntityState.DRAFT 88 assert question.flexo_id.version == 1 64 def test_obsolete_state(entity): 65 entity.approve() 66 entity.sign() 67 entity.publish() 68 entity.obsolete() 69 assert entity.state == EntityState.OBSOLETE 89 70 90 71 91 def test_mass_version_increments_until_obsolete(question): 92 question.approve() 72 def test_clone_new_base_resets_lineage(entity): 73 entity.approve() 74 entity.sign() 75 entity.publish() 76 entity.obsolete() 77 old_id = entity.flexo_id 78 entity.clone_new_base() 79 assert entity.flexo_id != old_id 80 assert entity.state == EntityState.DRAFT 81 assert entity.flexo_id.version == 1 82 83 84 def test_mass_version_increments_until_obsolete(entity): 85 entity.approve() 93 86 for _ in range(FlexOID.MAX_VERSION - 2): 94 question.sign()87 entity.sign() 95 88 with pytest.raises(RuntimeError, match="mark obsolete"): 96 question.sign()89 entity.sign()
Note:
See TracChangeset
for help on using the changeset viewer.
