| 1 | import pytest
|
|---|
| 2 | from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 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)
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 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
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | 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
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 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 |
|
|---|
| 41 |
|
|---|
| 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
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 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 |
|
|---|
| 55 |
|
|---|
| 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
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 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)
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 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 |
|
|---|
| 83 |
|
|---|
| 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()
|
|---|
| 100 | for _ in range(FlexOID.MAX_VERSION - 2):
|
|---|
| 101 | q.sign()
|
|---|
| 102 | with pytest.raises(RuntimeError, match="mark obsolete"):
|
|---|
| 103 | q.sign()
|
|---|