source: flexoentity/tests/test_id_lifecycle.py@ 37b5d11

Last change on this file since 37b5d11 was 4ceca57, checked in by Enrico Schwass <ennoausberlin@…>, 3 months ago

some tests improved

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[59342ce]1import pytest
[02d288d]2from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState
[59342ce]3
4
[02d288d]5# ──────────────────────────────────────────────────────────────────────────────
6# Tests adapted to use real RadioQuestion fixture instead of DummyEntity
7# ──────────────────────────────────────────────────────────────────────────────
[59342ce]8
[02d288d]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)
[59342ce]14
15
[02d288d]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
[59342ce]21
22
[02d288d]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
[59342ce]30
31
[02d288d]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
[59342ce]40
41
[02d288d]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
[59342ce]47
48
[02d288d]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
[59342ce]54
55
[02d288d]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
[59342ce]63
64
[02d288d]65def test_integrity_check_passes_and_fails(radio_question):
66 q = radio_question
67 q.approve()
68 assert FlexoEntity.verify_integrity(q)
[59342ce]69
[02d288d]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
[4ceca57]96def test_clone_new_base_sets_origin(radio_question):
97 q = radio_question
98 q.approve()
99 q.sign()
100 q.publish()
101 old_id = str(q.flexo_id)
102 q.obsolete()
103 q.clone_new_base()
104 assert q.origin == old_id
105 assert q.state == EntityState.DRAFT
106 assert q.flexo_id.version == 1
107 assert q.flexo_id != old_id
[02d288d]108
109def test_mass_version_increments_until_obsolete(radio_question):
110 q = radio_question
111 q.approve()
[59342ce]112 for _ in range(FlexOID.MAX_VERSION - 2):
[02d288d]113 q.sign()
[59342ce]114 with pytest.raises(RuntimeError, match="mark obsolete"):
[02d288d]115 q.sign()
Note: See TracBrowser for help on using the repository browser.