source: flexoentity/tests/test_id_lifecycle.py@ 59342ce

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

all tests green

  • Property mode set to 100644
File size: 3.0 KB
Line 
1import os
2import sys
3import pytest
4sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
5
6from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState
7
8
9@pytest.fixture
10def question():
11 """Fresh question entity in draft state."""
12 return FlexoEntity("AF", EntityType.QUESTION, "What is Ohm’s law?", EntityState.DRAFT)
13
14
15# ──────────────────────────────────────────────────────────────────────────────
16def test_initial_state(question):
17 assert question.state == EntityState.DRAFT
18 assert question.flexo_id.version == 1
19 assert len(question.flexo_id.signature) == 16 # blake2s digest_size=8 → 16 hex
20 assert FlexoEntity.verify_integrity(question)
21
22
23def test_approval_bumps_version(question):
24 question.approve()
25 assert question.state == EntityState.APPROVED
26 assert question.flexo_id.version == 2
27
28
29def test_signing_bumps_version(question):
30 question.approve()
31 v_before = question.flexo_id
32 question.sign()
33 assert question.state == EntityState.APPROVED_AND_SIGNED
34 assert question.flexo_id != v_before
35
36def test_publish_bumps_version(question):
37 question.approve()
38 question.sign()
39 v_before = question.flexo_id.version
40 question.publish()
41 assert question.state == EntityState.PUBLISHED
42 assert question.flexo_id.version == v_before + 1
43
44def test_modify_content_changes_fingerprint(question):
45 old_signature = question.flexo_id.signature
46 question.modify_content("Rephrased Ohm’s law?")
47 assert question.flexo_id.signature != old_signature
48
49
50def test_no_version_bump_on_draft_edits(question):
51 question.modify_content("Draft edit only")
52 assert question.flexo_id.version == 1
53
54
55def test_version_bump_after_edit_and_sign(question):
56 question.approve()
57 v1 = question.flexo_id
58 question.modify_content("Changed content")
59 question.sign()
60 assert question.flexo_id != v1
61
62
63def test_integrity_check_passes_and_fails(question):
64 question.approve()
65 assert FlexoEntity.verify_integrity(question)
66 # simulate tampering
67 question.text_seed = "Tampered text"
68 assert not FlexoEntity.verify_integrity(question)
69
70
71def test_obsolete_state(question):
72 question.approve()
73 question.sign()
74 question.publish()
75 question.obsolete()
76 assert question.state == EntityState.OBSOLETE
77
78
79def test_clone_new_base_resets_lineage(question):
80 question.approve()
81 question.sign()
82 question.publish()
83 question.obsolete()
84 old_id = question.flexo_id
85 question.clone_new_base()
86 assert question.flexo_id != old_id
87 assert question.state == EntityState.DRAFT
88 assert question.flexo_id.version == 1
89
90
91def test_mass_version_increments_until_obsolete(question):
92 question.approve()
93 for _ in range(FlexOID.MAX_VERSION - 2):
94 question.sign()
95 with pytest.raises(RuntimeError, match="mark obsolete"):
96 question.sign()
Note: See TracBrowser for help on using the repository browser.