Changeset 3389960 in flexoentity for tests


Ignore:
Timestamp:
02/27/26 13:47:23 (3 days ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
unify_backends
Children:
c1144fd
Parents:
54941b4
Message:

redesign of Identity and PersistanceBackends - this is a breaking change.

Location:
tests
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • tests/test_composite_backend.py

    r54941b4 r3389960  
    1010    backend = CompositeBackend(authoritative_backend=primary, sync_backends=[secondary])
    1111
    12     backend.save(sample_domain)
     12    backend.save(sample_domain.to_dict())
    1313
    1414    fid = sample_domain.flexo_id
     
    2525    backend = CompositeBackend(authoritative_backend=primary, sync_backends=[secondary])
    2626
    27     primary.save(sample_domain)
     27    primary.save(sample_domain.to_dict())
    2828
    2929    # secondary has nothing, but composite should still load from primary
    3030    fid = sample_domain.flexo_id
    31     loaded = backend.load(fid)
     31    loaded = Domain.from_dict(backend.load(fid))
    3232    assert isinstance(loaded, Domain)
    3333
     
    3939    backend = CompositeBackend(authoritative_backend=primary, sync_backends=[secondary])
    4040
    41     backend.save(sample_domain)
     41    backend.save(sample_domain.to_dict())
    4242
    4343    backend.clear()
  • tests/test_flexoid.py

    r54941b4 r3389960  
    1313import pytest
    1414from logging import Logger
    15 from flexoentity import FlexOID, canonical_seed
     15from flexoentity import FlexOID, canonical_seed, Domain
    1616
    1717
     
    5151# Generation and deterministic hashing
    5252# ──────────────────────────────────────────────
    53 
    54 def test_generate_and_hash_stability(fixed_datetime):
    55     # Fix the date so test is stable
     53def test_generate_is_not_deterministic(fixed_datetime):
    5654    fid1 = FlexOID.generate("GEN", "I", "D", "test content")
    5755    fid2 = FlexOID.generate("GEN", "I", "D", "test content")
    58     assert fid1 == fid2  # deterministic
    59     assert fid1.hash_part == fid2.hash_part
    60     assert fid1.domain_id == "GEN"
    61     assert fid1.entity_type == "I"
    6256
     57    assert fid1 != fid2
     58    assert fid1.domain_id == fid2.domain_id == "GEN"
     59    assert fid1.entity_type == fid2.entity_type == "I"
     60    assert fid1.version == fid2.version == 1
     61    assert fid1.state_code == fid2.state_code == "D"
     62
     63def test_fingerprint_is_stable():
     64    d1 = Domain.with_domain_id("GEN", fullname="A", description="B")
     65    d2 = Domain.from_dict(d1.to_dict())
     66
     67    assert d1.fingerprint == d2.fingerprint
    6368
    6469def test_safe_generate_collision(monkeypatch):
    65     # Fake repo that always returns a conflicting item with different seed
    66     class DummyRepo(dict):
    67         def get(self, key): return True
     70    first = FlexOID.generate("GEN", "I", "D", "abc")
     71
     72    class DummyRepo:
     73        def get(self, key):
     74            if key == str(first):
     75                return True
     76            return None
    6877
    6978    repo = DummyRepo()
     79
    7080    fid = FlexOID.safe_generate("GEN", "I", "D", "abc", repo=repo)
     81
    7182    assert isinstance(fid, FlexOID)
     83    assert fid != first
    7284    assert fid.state_code == "D"
    73 
    7485
    7586# ──────────────────────────────────────────────
  • tests/test_id_stress.py

    r54941b4 r3389960  
    5252    assert all("@" in id_str for id_str in ids)
    5353
    54 def test_id_generation_is_deterministic(sample_domain):
    55     """
    56     Generating the same entity twice with same inputs yields identical ID.
    57     (No runtime disambiguation; IDs are deterministic by design.)
    58     """
    59     entity_type = EntityType.ITEM
    60     estate = EntityState.DRAFT
    61     text = "identical question text"
     54# def test_id_generation_is_deterministic(sample_domain):
     55#     """
     56#     Generating the same entity twice with same inputs yields identical ID.
     57#     (No runtime disambiguation; IDs are deterministic by design.)
     58#     """
     59#     entity_type = EntityType.ITEM
     60#     estate = EntityState.DRAFT
     61#     text = "identical question text"
    6262
    63     id1 = FlexOID.generate(sample_domain.domain_id, entity_type.value, estate.value, text)
    64     id2 = FlexOID.generate(sample_domain.domain_id, entity_type.value, estate.value, text)
    65     # IDs must be identical because generation is deterministic
    66     assert id1 == id2
     63#     id1 = FlexOID.generate(sample_domain.domain_id, entity_type.value, estate.value, text)
     64#     id2 = FlexOID.generate(sample_domain.domain_id, entity_type.value, estate.value, text)
     65#     # IDs must be identical because generation is deterministic
     66#     assert id1 == id2
    6767
    6868def test_massive_lifecycle_simulation(cert_ref_linux, sample_domain):
  • tests/test_in_memory_backend.py

    r54941b4 r3389960  
    77
    88def test_save_and_load_roundtrip(local_backend, sample_domain):
    9     local_backend.save(sample_domain)
     9    local_backend.save(sample_domain.to_dict())
    1010
    11     loaded = local_backend.load(sample_domain.flexo_id)
     11    loaded_dict = local_backend.load(sample_domain.flexo_id)
     12    loaded = Domain.from_dict(loaded_dict)
     13
    1214    assert isinstance(loaded, Domain)
    13     # important: entity equality is probably identity-based, so compare dicts:
    14     assert loaded.to_dict() == sample_domain.to_dict()
    15 
    16 
     15    assert loaded == sample_domain
     16   
    1717def test_update_overwrites_entity(local_backend, sample_domain):
    18     local_backend.save(sample_domain)
     18    local_backend.save(sample_domain.to_dict())
    1919
    2020    # change something
    2121    sample_domain.description = "UPDATED DESC"
    22     local_backend.update(sample_domain)
     22    local_backend.update(sample_domain.to_dict())
    2323
    24     loaded = local_backend.load(sample_domain.flexo_id)
     24    loaded = Domain.from_dict(local_backend.load(sample_domain.flexo_id))
    2525    assert loaded.description == "UPDATED DESC"
    2626
    2727
    2828def test_delete_removes_entity(local_backend, sample_domain):
    29     local_backend.save(sample_domain)
     29    local_backend.save(sample_domain.to_dict())
    3030    local_backend.delete(sample_domain.flexo_id)
    3131
     
    3535
    3636def test_clear_removes_all(local_backend, sample_domain):
    37     local_backend.save(sample_domain)
     37    local_backend.save(sample_domain.to_dict())
    3838    local_backend.clear()
    3939
  • tests/test_json_file_backend.py

    r54941b4 r3389960  
    2222    dom2 = make_domain("PY_STRINGS")
    2323
    24     backend.save(dom1)
    25     backend.save(dom2)
     24    backend.save(dom1.to_dict())
     25    backend.save(dom2.to_dict())
    2626    backend.flush_to_file()
    2727
     
    2929    backend2 = JsonFileBackend(Domain, path)
    3030    backend2.load_from_file()
    31 
    32     loaded = backend2.load_all()
    33     ids = sorted(d.domain_id for d in loaded)
     31    loaded_dicts = backend2.load_all()
     32    domains = [Domain.from_dict(d) for d in loaded_dicts]
     33    ids = sorted(d.domain_id for d in domains)
    3434    assert ids == ["PY_ARITHM", "PY_STRINGS"]
  • tests/test_sqlite_backend.py

    r54941b4 r3389960  
    44
    55
    6 def make_domain(domain_id="PY_ARITHM"):
    7     return Domain.with_domain_id(
    8         subtype="Domain",
    9         domain_id=domain_id,
    10         fullname="PYTHON_ARITHMETIC",
    11         description="ALL ABOUT ARITHMETIC IN PYTHON",
    12         classification="UNCLASSIFIED",
    13     )
    14 
    15 
    16 def test_sqlite_roundtrip(tmp_path):
     6def test_sqlite_roundtrip(tmp_path, sample_domain):
    177    db_path = tmp_path / "domains.db"
    188    conn = sqlite3.connect(db_path)
     
    2111    backend = SQLiteEntityBackend(Domain, conn, table_name="domains")
    2212
    23     dom = make_domain()
    24     backend.save(dom)
     13    backend.save(sample_domain.to_dict())
    2514
    26     loaded = backend.load(dom.flexo_id)
    27     assert loaded.to_dict() == dom.to_dict()
     15    loaded = backend.load(sample_domain.flexo_id)
     16    assert loaded == sample_domain.to_dict()
    2817
    2918    all_loaded = backend.load_all()
    3019    assert len(all_loaded) == 1
    31     assert all_loaded[0].domain_id == "PY_ARITHM"
     20    assert Domain.from_dict(all_loaded[0]).domain_id == "PY_ARITHM"
Note: See TracChangeset for help on using the changeset viewer.