| 1 | import pytest
|
|---|
| 2 | from flexoentity import FlexOID, FlexoEntity, EntityState
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 | def test_initial_state(sample_domain):
|
|---|
| 6 | assert sample_domain.state == EntityState.DRAFT
|
|---|
| 7 | assert sample_domain.flexo_id.version == 1
|
|---|
| 8 | assert FlexoEntity.verify_integrity(sample_domain)
|
|---|
| 9 |
|
|---|
| 10 | def test_approval_does_not_bump_version(sample_domain):
|
|---|
| 11 | q = sample_domain
|
|---|
| 12 | q.approve()
|
|---|
| 13 | assert q.state == EntityState.APPROVED
|
|---|
| 14 | assert q.flexo_id.version == 1
|
|---|
| 15 |
|
|---|
| 16 | def test_signing_does_not_bump_version(sample_domain):
|
|---|
| 17 | q = sample_domain
|
|---|
| 18 | q.approve()
|
|---|
| 19 | before = q.flexo_id
|
|---|
| 20 | q.sign()
|
|---|
| 21 | after = q.flexo_id
|
|---|
| 22 |
|
|---|
| 23 | # state changed
|
|---|
| 24 | assert q.state == EntityState.APPROVED_AND_SIGNED
|
|---|
| 25 |
|
|---|
| 26 | # version unchanged
|
|---|
| 27 | assert before.version == after.version
|
|---|
| 28 |
|
|---|
| 29 | # only suffix letter differs
|
|---|
| 30 | assert before.prefix == after.prefix
|
|---|
| 31 | assert before.state_code == "A"
|
|---|
| 32 | assert after.state_code == "S"
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | def test_publish_does_not_bump_version(sample_domain):
|
|---|
| 36 | q = sample_domain
|
|---|
| 37 | q.approve()
|
|---|
| 38 | q.sign()
|
|---|
| 39 | v_before = q.flexo_id.version
|
|---|
| 40 | q.publish()
|
|---|
| 41 | assert q.state == EntityState.PUBLISHED
|
|---|
| 42 | assert q.flexo_id.version == v_before
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | def test_modify_content_changes_fingerprint(sample_signature):
|
|---|
| 46 | sample_signature.comment += "Rephrased content" # simulate text change
|
|---|
| 47 | changed = sample_signature._update_fingerprint()
|
|---|
| 48 | assert changed
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | def test_no_version_bump_on_draft_edits(sample_signature):
|
|---|
| 52 | sample_signature.comment = "Minor draft edit"
|
|---|
| 53 | sample_signature._update_fingerprint()
|
|---|
| 54 | assert sample_signature.flexo_id.version == 1
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | def test_version_bump_after_edit_and_sign(sample_signature):
|
|---|
| 58 | sample_signature.approve()
|
|---|
| 59 | v1 = str(sample_signature.flexo_id)
|
|---|
| 60 | sample_signature.comment = "Changed comment"
|
|---|
| 61 | sample_signature.sign()
|
|---|
| 62 | assert str(sample_signature.flexo_id) != v1
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 | def test_integrity_check_passes_and_fails(sample_signature):
|
|---|
| 66 | sample_signature.approve()
|
|---|
| 67 | assert FlexoEntity.verify_integrity(sample_signature)
|
|---|
| 68 |
|
|---|
| 69 | # simulate tampering
|
|---|
| 70 | sample_signature.comment = "Tampered text"
|
|---|
| 71 | assert not FlexoEntity.verify_integrity(sample_signature)
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | def test_obsolete_state(sample_domain):
|
|---|
| 75 | q = sample_domain
|
|---|
| 76 | q.approve()
|
|---|
| 77 | q.sign()
|
|---|
| 78 | q.publish()
|
|---|
| 79 | q.obsolete()
|
|---|
| 80 | assert q.state == EntityState.OBSOLETE
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | def test_clone_new_base_resets_lineage(sample_domain):
|
|---|
| 84 | q = sample_domain
|
|---|
| 85 | q.approve()
|
|---|
| 86 | q.sign()
|
|---|
| 87 | q.publish()
|
|---|
| 88 | q.obsolete()
|
|---|
| 89 | old_id = str(q.flexo_id)
|
|---|
| 90 | q.clone_new_base()
|
|---|
| 91 | assert str(q.flexo_id) != old_id
|
|---|
| 92 | assert q.state == EntityState.DRAFT
|
|---|
| 93 | assert q.flexo_id.version == 1
|
|---|
| 94 |
|
|---|
| 95 | def test_clone_new_base_sets_origin(sample_domain):
|
|---|
| 96 | q = sample_domain
|
|---|
| 97 | q.approve()
|
|---|
| 98 | q.sign()
|
|---|
| 99 | q.publish()
|
|---|
| 100 | q.obsolete()
|
|---|
| 101 | old_id = str(q.flexo_id)
|
|---|
| 102 | q.clone_new_base()
|
|---|
| 103 | assert q.origin == old_id
|
|---|
| 104 | assert q.state == EntityState.DRAFT
|
|---|
| 105 | assert q.flexo_id.version == 1
|
|---|
| 106 | assert q.flexo_id != old_id
|
|---|
| 107 |
|
|---|
| 108 | def test_mass_version_increments_until_obsolete(sample_domain):
|
|---|
| 109 | q = sample_domain
|
|---|
| 110 | q.approve()
|
|---|
| 111 | for _ in range(FlexOID.MAX_VERSION - 1):
|
|---|
| 112 | q.bump_version()
|
|---|
| 113 |
|
|---|
| 114 | # Next one must raise
|
|---|
| 115 | with pytest.raises(RuntimeError, match="mark obsolete"):
|
|---|
| 116 | q.bump_version()
|
|---|