Changeset 02d288d in flexoentity for tests/test_id_lifecycle.py
- Timestamp:
- 10/23/25 13:27:08 (3 months ago)
- Branches:
- master
- Children:
- 4ceca57
- Parents:
- 6a7dec1
- File:
-
- 1 edited
-
tests/test_id_lifecycle.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tests/test_id_lifecycle.py
r6a7dec1 r02d288d 1 1 import pytest 2 3 from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState 4 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) 2 from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState 10 3 11 4 12 def test_approval_bumps_version(entity): 13 entity.approve() 14 assert entity.state == EntityState.APPROVED 15 assert entity.flexo_id.version == 2 5 # ────────────────────────────────────────────────────────────────────────────── 6 # Tests adapted to use real RadioQuestion fixture instead of DummyEntity 7 # ────────────────────────────────────────────────────────────────────────────── 8 9 def test_initial_state(radio_question): 10 q = radio_question 11 assert q.state == EntityState.DRAFT 12 assert q.flexo_id.version == 1 13 assert FlexoEntity.verify_integrity(q) 16 14 17 15 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 16 def test_approval_bumps_version(radio_question): 17 q = radio_question 18 q.approve() 19 assert q.state == EntityState.APPROVED 20 assert q.flexo_id.version == 2 24 21 25 22 26 def test_ publish_bumps_version(entity):27 entity.approve()28 entity.sign()29 v_before = entity.flexo_id.version30 entity.publish()31 assert entity.state == EntityState.PUBLISHED32 assert entity.flexo_id.version == v_before + 123 def test_signing_bumps_version(radio_question): 24 q = radio_question 25 q.approve() 26 v_before = str(q.flexo_id) 27 q.sign() 28 assert q.state == EntityState.APPROVED_AND_SIGNED 29 assert str(q.flexo_id) != v_before 33 30 34 31 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 32 def test_publish_bumps_version(radio_question): 33 q = radio_question 34 q.approve() 35 q.sign() 36 v_before = q.flexo_id.version 37 q.publish() 38 assert q.state == EntityState.PUBLISHED 39 assert q.flexo_id.version == v_before + 1 40 40 41 41 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 42 def test_modify_content_changes_fingerprint(radio_question): 43 q = radio_question 44 q.text = "Rephrased content" # simulate text change 45 changed = q._update_fingerprint() 46 assert changed 46 47 47 48 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 49 def test_no_version_bump_on_draft_edits(radio_question): 50 q = radio_question 51 q.text = "Minor draft edit" 52 q._update_fingerprint() 53 assert q.flexo_id.version == 1 54 54 55 55 56 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) 56 def test_version_bump_after_edit_and_sign(radio_question): 57 q = radio_question 58 q.approve() 59 v1 = str(q.flexo_id) 60 q.text = "Changed content" 61 q.sign() 62 assert str(q.flexo_id) != v1 62 63 63 64 64 def test_obsolete_state(entity): 65 entity.approve() 66 entity.sign() 67 entity.publish() 68 entity.obsolete() 69 assert entity.state == EntityState.OBSOLETE 65 def test_integrity_check_passes_and_fails(radio_question): 66 q = radio_question 67 q.approve() 68 assert FlexoEntity.verify_integrity(q) 69 70 # simulate tampering 71 q.text = "Tampered text" 72 assert not FlexoEntity.verify_integrity(q) 70 73 71 74 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 75 def test_obsolete_state(radio_question): 76 q = radio_question 77 q.approve() 78 q.sign() 79 q.publish() 80 q.obsolete() 81 assert q.state == EntityState.OBSOLETE 82 82 83 83 84 def test_mass_version_increments_until_obsolete(entity): 85 entity.approve() 84 def test_clone_new_base_resets_lineage(radio_question): 85 q = radio_question 86 q.approve() 87 q.sign() 88 q.publish() 89 q.obsolete() 90 old_id = str(q.flexo_id) 91 q.clone_new_base() 92 assert str(q.flexo_id) != old_id 93 assert q.state == EntityState.DRAFT 94 assert q.flexo_id.version == 1 95 96 97 def test_mass_version_increments_until_obsolete(radio_question): 98 q = radio_question 99 q.approve() 86 100 for _ in range(FlexOID.MAX_VERSION - 2): 87 entity.sign()101 q.sign() 88 102 with pytest.raises(RuntimeError, match="mark obsolete"): 89 entity.sign()103 q.sign()
Note:
See TracChangeset
for help on using the changeset viewer.
