Changeset 8a238e2 in flexoentity for tests/test_id_lifecycle.py


Ignore:
Timestamp:
10/20/25 13:15:45 (3 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
master
Children:
3d65ce5
Parents:
045b864
Message:

skip some tests due to missing correct serialized entities

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/test_id_lifecycle.py

    r045b864 r8a238e2  
    1 import os
    2 import sys
    31import pytest
    4 sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
    52
    63from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState
    74
    8 
    9 @pytest.fixture
    10 def question():
    11     """Fresh question entity in draft state."""
    12     return FlexoEntity("AF", EntityType.QUESTION, "What is Ohm’s law?", EntityState.DRAFT)
     5def test_initial_state(entity):
     6    assert entity.state == EntityState.DRAFT
     7    assert entity.flexo_id.version == 1
     8    assert len(entity.flexo_id.signature) == 16  # blake2s digest_size=8 → 16 hex
     9    assert FlexoEntity.verify_integrity(entity)
    1310
    1411
    15 # ──────────────────────────────────────────────────────────────────────────────
    16 def 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)
     12def test_approval_bumps_version(entity):
     13    entity.approve()
     14    assert entity.state == EntityState.APPROVED
     15    assert entity.flexo_id.version == 2
    2116
    2217
    23 def test_approval_bumps_version(question):
    24     question.approve()
    25     assert question.state == EntityState.APPROVED
    26     assert question.flexo_id.version == 2
     18def test_signing_bumps_version(entity):
     19    entity.approve()
     20    v_before = entity.flexo_id
     21    entity.sign()
     22    assert entity.state == EntityState.APPROVED_AND_SIGNED
     23    assert entity.flexo_id != v_before
    2724
    2825
    29 def 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 
    36 def 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 
    44 def 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
     26def test_publish_bumps_version(entity):
     27    entity.approve()
     28    entity.sign()
     29    v_before = entity.flexo_id.version
     30    entity.publish()
     31    assert entity.state == EntityState.PUBLISHED
     32    assert entity.flexo_id.version == v_before + 1
    4833
    4934
    50 def test_no_version_bump_on_draft_edits(question):
    51     question.modify_content("Draft edit only")
    52     assert question.flexo_id.version == 1
     35def test_modify_content_changes_fingerprint(entity):
     36    old_signature = entity.flexo_id.signature
     37    entity._seed = "Rephrased content"  # simulate text change
     38    entity._update_fingerprint()
     39    assert entity.flexo_id.signature != old_signature
    5340
    5441
    55 def 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
     42def test_no_version_bump_on_draft_edits(entity):
     43    entity._seed = "Draft edit only"
     44    entity._update_fingerprint()
     45    assert entity.flexo_id.version == 1
    6146
    6247
    63 def 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)
     48def test_version_bump_after_edit_and_sign(entity):
     49    entity.approve()
     50    v1 = entity.flexo_id
     51    entity._seed = "Changed content"
     52    entity.sign()
     53    assert entity.flexo_id != v1
    6954
    7055
    71 def test_obsolete_state(question):
    72     question.approve()
    73     question.sign()
    74     question.publish()
    75     question.obsolete()
    76     assert question.state == EntityState.OBSOLETE
     56def test_integrity_check_passes_and_fails(entity):
     57    entity.approve()
     58    assert FlexoEntity.verify_integrity(entity)
     59    # simulate tampering
     60    entity._seed = "Tampered text"
     61    assert not FlexoEntity.verify_integrity(entity)
    7762
    7863
    79 def 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
     64def test_obsolete_state(entity):
     65    entity.approve()
     66    entity.sign()
     67    entity.publish()
     68    entity.obsolete()
     69    assert entity.state == EntityState.OBSOLETE
    8970
    9071
    91 def test_mass_version_increments_until_obsolete(question):
    92     question.approve()
     72def test_clone_new_base_resets_lineage(entity):
     73    entity.approve()
     74    entity.sign()
     75    entity.publish()
     76    entity.obsolete()
     77    old_id = entity.flexo_id
     78    entity.clone_new_base()
     79    assert entity.flexo_id != old_id
     80    assert entity.state == EntityState.DRAFT
     81    assert entity.flexo_id.version == 1
     82
     83
     84def test_mass_version_increments_until_obsolete(entity):
     85    entity.approve()
    9386    for _ in range(FlexOID.MAX_VERSION - 2):
    94         question.sign()
     87        entity.sign()
    9588    with pytest.raises(RuntimeError, match="mark obsolete"):
    96         question.sign()
     89        entity.sign()
Note: See TracChangeset for help on using the changeset viewer.