source: flexoentity/tests/test_id_lifecycle.py@ 4af65b0

Last change on this file since 4af65b0 was 4af65b0, checked in by Enrico Schwass <ennoausberlin@…>, 2 months ago

initial logging support

  • Property mode set to 100644
File size: 3.5 KB
Line 
1import pytest
2from flexoentity import FlexOID, FlexoEntity, EntityState
3
4
5# ──────────────────────────────────────────────────────────────────────────────
6# Tests adapted to use real SingleChoiceQuestion fixture instead of DummyEntity
7# ──────────────────────────────────────────────────────────────────────────────
8
9def test_initial_state(sample_question):
10 q = sample_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_does_not_bump_version(sample_question):
17 q = sample_question
18 q.approve()
19 assert q.state == EntityState.APPROVED
20 assert q.flexo_id.version == 1
21
22def test_signing_does_not_bump_version(sample_question):
23 q = sample_question
24 q.approve()
25 before = q.flexo_id
26 q.sign()
27 after = q.flexo_id
28
29 # state changed
30 assert q.state == EntityState.APPROVED_AND_SIGNED
31
32 # version unchanged
33 assert before.version == after.version
34
35 # only suffix letter differs
36 assert before.prefix == after.prefix
37 assert before.state_code == "A"
38 assert after.state_code == "S"
39
40
41def test_publish_does_not_bump_version(sample_question):
42 q = sample_question
43 q.approve()
44 q.sign()
45 v_before = q.flexo_id.version
46 q.publish()
47 assert q.state == EntityState.PUBLISHED
48 assert q.flexo_id.version == v_before
49
50
51def test_modify_content_changes_fingerprint(sample_question):
52 q = sample_question
53 q.text += "Rephrased content" # simulate text change
54 changed = q._update_fingerprint()
55 assert changed
56
57
58def test_no_version_bump_on_draft_edits(sample_question):
59 q = sample_question
60 q.text = "Minor draft edit"
61 q._update_fingerprint()
62 assert q.flexo_id.version == 1
63
64
65def test_version_bump_after_edit_and_sign(sample_question):
66 q = sample_question
67 q.approve()
68 v1 = str(q.flexo_id)
69 q.text = "Changed content"
70 q.sign()
71 assert str(q.flexo_id) != v1
72
73
74def test_integrity_check_passes_and_fails(sample_question):
75 q = sample_question
76 q.approve()
77 assert FlexoEntity.verify_integrity(q)
78
79 # simulate tampering
80 q.text = "Tampered text"
81 assert not FlexoEntity.verify_integrity(q)
82
83
84def test_obsolete_state(sample_question):
85 q = sample_question
86 q.approve()
87 q.sign()
88 q.publish()
89 q.obsolete()
90 assert q.state == EntityState.OBSOLETE
91
92
93def test_clone_new_base_resets_lineage(sample_question):
94 q = sample_question
95 q.approve()
96 q.sign()
97 q.publish()
98 q.obsolete()
99 old_id = str(q.flexo_id)
100 q.clone_new_base()
101 assert str(q.flexo_id) != old_id
102 assert q.state == EntityState.DRAFT
103 assert q.flexo_id.version == 1
104
105def test_clone_new_base_sets_origin(sample_question):
106 q = sample_question
107 q.approve()
108 q.sign()
109 q.publish()
110 q.obsolete()
111 old_id = str(q.flexo_id)
112 q.clone_new_base()
113 assert q.origin == old_id
114 assert q.state == EntityState.DRAFT
115 assert q.flexo_id.version == 1
116 assert q.flexo_id != old_id
117
118def test_mass_version_increments_until_obsolete(sample_question):
119 q = sample_question
120 q.approve()
121 for _ in range(FlexOID.MAX_VERSION - 1):
122 q.bump_version()
123
124 # Next one must raise
125 with pytest.raises(RuntimeError, match="mark obsolete"):
126 q.bump_version()
Note: See TracBrowser for help on using the repository browser.