Changeset 02d288d in flexoentity for tests/test_id_lifecycle.py


Ignore:
Timestamp:
10/23/25 13:27:08 (3 months ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
master
Children:
4ceca57
Parents:
6a7dec1
Message:

improve hash generation and collision handler - move signature from FlexOID to FlexoEntity

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/test_id_lifecycle.py

    r6a7dec1 r02d288d  
    11import pytest
    2 
    3 from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState
    4 
    5 def 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)
     2from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState
    103
    114
    12 def test_approval_bumps_version(entity):
    13     entity.approve()
    14     assert entity.state == EntityState.APPROVED
    15     assert entity.flexo_id.version == 2
     5# ──────────────────────────────────────────────────────────────────────────────
     6# Tests adapted to use real RadioQuestion fixture instead of DummyEntity
     7# ──────────────────────────────────────────────────────────────────────────────
     8
     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)
    1614
    1715
    18 def 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
     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
    2421
    2522
    26 def 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
     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
    3330
    3431
    35 def 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
     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
    4040
    4141
    42 def 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
     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
    4647
    4748
    48 def 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
     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
    5454
    5555
    56 def 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)
     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
    6263
    6364
    64 def test_obsolete_state(entity):
    65     entity.approve()
    66     entity.sign()
    67     entity.publish()
    68     entity.obsolete()
    69     assert entity.state == EntityState.OBSOLETE
     65def test_integrity_check_passes_and_fails(radio_question):
     66    q = radio_question
     67    q.approve()
     68    assert FlexoEntity.verify_integrity(q)
     69
     70    # simulate tampering
     71    q.text = "Tampered text"
     72    assert not FlexoEntity.verify_integrity(q)
    7073
    7174
    72 def 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
     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
    8282
    8383
    84 def test_mass_version_increments_until_obsolete(entity):
    85     entity.approve()
     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
     96
     97def test_mass_version_increments_until_obsolete(radio_question):
     98    q = radio_question
     99    q.approve()
    86100    for _ in range(FlexOID.MAX_VERSION - 2):
    87         entity.sign()
     101        q.sign()
    88102    with pytest.raises(RuntimeError, match="mark obsolete"):
    89         entity.sign()
     103        q.sign()
Note: See TracChangeset for help on using the changeset viewer.