source: flexoentity/tests/test_id_lifecycle.py@ 02d288d

Last change on this file since 02d288d was 02d288d, checked in by Enrico Schwass <ennoausberlin@…>, 3 months ago

improve hash generation and collision handler - move signature from FlexOID to FlexoEntity

  • Property mode set to 100644
File size: 2.9 KB
Line 
1import pytest
2from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState
3
4
5# ──────────────────────────────────────────────────────────────────────────────
6# Tests adapted to use real RadioQuestion fixture instead of DummyEntity
7# ──────────────────────────────────────────────────────────────────────────────
8
9def 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
16def 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
23def 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
32def 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
42def 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
49def 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
56def 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
65def 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
75def 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
84def 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
97def 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()
Note: See TracBrowser for help on using the repository browser.