source: flexoentity/tests/test_id_lifecycle.py@ a475496

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

adjustments to domain handling - with_domain constructor added

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