source: flexoentity/tests/test_id_lifecycle.py@ bf30018

main unify_backends
Last change on this file since bf30018 was 5c72356, checked in by Enrico Schwass <ennoausberlin@…>, 4 months ago

fix tests due to simplifying state and type

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