| [59342ce] | 1 | import pytest
|
|---|
| [8aa20c7] | 2 | from flexoentity import FlexOID, FlexoEntity, EntityState
|
|---|
| [59342ce] | 3 |
|
|---|
| 4 |
|
|---|
| [ef964d8] | 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)
|
|---|
| [59342ce] | 9 |
|
|---|
| [ef964d8] | 10 | def test_approval_does_not_bump_version(sample_domain):
|
|---|
| 11 | q = sample_domain
|
|---|
| [02d288d] | 12 | q.approve()
|
|---|
| 13 | assert q.state == EntityState.APPROVED
|
|---|
| [8aa20c7] | 14 | assert q.flexo_id.version == 1
|
|---|
| [59342ce] | 15 |
|
|---|
| [ef964d8] | 16 | def test_signing_does_not_bump_version(sample_domain):
|
|---|
| 17 | q = sample_domain
|
|---|
| [02d288d] | 18 | q.approve()
|
|---|
| [5c72356] | 19 | before = q.flexo_id
|
|---|
| [02d288d] | 20 | q.sign()
|
|---|
| [5c72356] | 21 | after = q.flexo_id
|
|---|
| 22 |
|
|---|
| 23 | # state changed
|
|---|
| [02d288d] | 24 | assert q.state == EntityState.APPROVED_AND_SIGNED
|
|---|
| [59342ce] | 25 |
|
|---|
| [5c72356] | 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"
|
|---|
| [59342ce] | 33 |
|
|---|
| [5c72356] | 34 |
|
|---|
| [ef964d8] | 35 | def test_publish_does_not_bump_version(sample_domain):
|
|---|
| 36 | q = sample_domain
|
|---|
| [02d288d] | 37 | q.approve()
|
|---|
| 38 | q.sign()
|
|---|
| 39 | v_before = q.flexo_id.version
|
|---|
| 40 | q.publish()
|
|---|
| 41 | assert q.state == EntityState.PUBLISHED
|
|---|
| [5c72356] | 42 | assert q.flexo_id.version == v_before
|
|---|
| [59342ce] | 43 |
|
|---|
| 44 |
|
|---|
| [ef964d8] | 45 | def test_modify_content_changes_fingerprint(sample_signature):
|
|---|
| 46 | sample_signature.comment += "Rephrased content" # simulate text change
|
|---|
| 47 | changed = sample_signature._update_fingerprint()
|
|---|
| [02d288d] | 48 | assert changed
|
|---|
| [59342ce] | 49 |
|
|---|
| 50 |
|
|---|
| [ef964d8] | 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
|
|---|
| [59342ce] | 55 |
|
|---|
| 56 |
|
|---|
| [ef964d8] | 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
|
|---|
| [59342ce] | 63 |
|
|---|
| 64 |
|
|---|
| [ef964d8] | 65 | def test_integrity_check_passes_and_fails(sample_signature):
|
|---|
| 66 | sample_signature.approve()
|
|---|
| 67 | assert FlexoEntity.verify_integrity(sample_signature)
|
|---|
| [59342ce] | 68 |
|
|---|
| [02d288d] | 69 | # simulate tampering
|
|---|
| [ef964d8] | 70 | sample_signature.comment = "Tampered text"
|
|---|
| 71 | assert not FlexoEntity.verify_integrity(sample_signature)
|
|---|
| [02d288d] | 72 |
|
|---|
| 73 |
|
|---|
| [ef964d8] | 74 | def test_obsolete_state(sample_domain):
|
|---|
| 75 | q = sample_domain
|
|---|
| [02d288d] | 76 | q.approve()
|
|---|
| 77 | q.sign()
|
|---|
| 78 | q.publish()
|
|---|
| 79 | q.obsolete()
|
|---|
| 80 | assert q.state == EntityState.OBSOLETE
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| [ef964d8] | 83 | def test_clone_new_base_resets_lineage(sample_domain):
|
|---|
| 84 | q = sample_domain
|
|---|
| [02d288d] | 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 |
|
|---|
| [ef964d8] | 95 | def test_clone_new_base_sets_origin(sample_domain):
|
|---|
| 96 | q = sample_domain
|
|---|
| [4ceca57] | 97 | q.approve()
|
|---|
| 98 | q.sign()
|
|---|
| 99 | q.publish()
|
|---|
| 100 | q.obsolete()
|
|---|
| [ca39274] | 101 | old_id = str(q.flexo_id)
|
|---|
| [4ceca57] | 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
|
|---|
| [02d288d] | 107 |
|
|---|
| [ef964d8] | 108 | def test_mass_version_increments_until_obsolete(sample_domain):
|
|---|
| 109 | q = sample_domain
|
|---|
| [02d288d] | 110 | q.approve()
|
|---|
| [8aa20c7] | 111 | for _ in range(FlexOID.MAX_VERSION - 1):
|
|---|
| [e198832] | 112 | q.bump_version()
|
|---|
| [5c72356] | 113 |
|
|---|
| 114 | # Next one must raise
|
|---|
| [59342ce] | 115 | with pytest.raises(RuntimeError, match="mark obsolete"):
|
|---|
| [5c72356] | 116 | q.bump_version()
|
|---|