- Timestamp:
- 02/27/26 13:47:23 (3 days ago)
- Branches:
- unify_backends
- Children:
- c1144fd
- Parents:
- 54941b4
- Location:
- tests
- Files:
-
- 6 edited
-
test_composite_backend.py (modified) (3 diffs)
-
test_flexoid.py (modified) (2 diffs)
-
test_id_stress.py (modified) (1 diff)
-
test_in_memory_backend.py (modified) (2 diffs)
-
test_json_file_backend.py (modified) (2 diffs)
-
test_sqlite_backend.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/test_composite_backend.py
r54941b4 r3389960 10 10 backend = CompositeBackend(authoritative_backend=primary, sync_backends=[secondary]) 11 11 12 backend.save(sample_domain )12 backend.save(sample_domain.to_dict()) 13 13 14 14 fid = sample_domain.flexo_id … … 25 25 backend = CompositeBackend(authoritative_backend=primary, sync_backends=[secondary]) 26 26 27 primary.save(sample_domain )27 primary.save(sample_domain.to_dict()) 28 28 29 29 # secondary has nothing, but composite should still load from primary 30 30 fid = sample_domain.flexo_id 31 loaded = backend.load(fid)31 loaded = Domain.from_dict(backend.load(fid)) 32 32 assert isinstance(loaded, Domain) 33 33 … … 39 39 backend = CompositeBackend(authoritative_backend=primary, sync_backends=[secondary]) 40 40 41 backend.save(sample_domain )41 backend.save(sample_domain.to_dict()) 42 42 43 43 backend.clear() -
tests/test_flexoid.py
r54941b4 r3389960 13 13 import pytest 14 14 from logging import Logger 15 from flexoentity import FlexOID, canonical_seed 15 from flexoentity import FlexOID, canonical_seed, Domain 16 16 17 17 … … 51 51 # Generation and deterministic hashing 52 52 # ────────────────────────────────────────────── 53 54 def test_generate_and_hash_stability(fixed_datetime): 55 # Fix the date so test is stable 53 def test_generate_is_not_deterministic(fixed_datetime): 56 54 fid1 = FlexOID.generate("GEN", "I", "D", "test content") 57 55 fid2 = FlexOID.generate("GEN", "I", "D", "test content") 58 assert fid1 == fid2 # deterministic59 assert fid1.hash_part == fid2.hash_part60 assert fid1.domain_id == "GEN"61 assert fid1.entity_type == "I"62 56 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 63 def 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 63 68 64 69 def 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 68 77 69 78 repo = DummyRepo() 79 70 80 fid = FlexOID.safe_generate("GEN", "I", "D", "abc", repo=repo) 81 71 82 assert isinstance(fid, FlexOID) 83 assert fid != first 72 84 assert fid.state_code == "D" 73 74 85 75 86 # ────────────────────────────────────────────── -
tests/test_id_stress.py
r54941b4 r3389960 52 52 assert all("@" in id_str for id_str in ids) 53 53 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.ITEM60 estate = EntityState.DRAFT61 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" 62 62 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 deterministic66 assert id1 == id263 # 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 67 67 68 68 def test_massive_lifecycle_simulation(cert_ref_linux, sample_domain): -
tests/test_in_memory_backend.py
r54941b4 r3389960 7 7 8 8 def test_save_and_load_roundtrip(local_backend, sample_domain): 9 local_backend.save(sample_domain )9 local_backend.save(sample_domain.to_dict()) 10 10 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 12 14 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 17 17 def test_update_overwrites_entity(local_backend, sample_domain): 18 local_backend.save(sample_domain )18 local_backend.save(sample_domain.to_dict()) 19 19 20 20 # change something 21 21 sample_domain.description = "UPDATED DESC" 22 local_backend.update(sample_domain )22 local_backend.update(sample_domain.to_dict()) 23 23 24 loaded = local_backend.load(sample_domain.flexo_id)24 loaded = Domain.from_dict(local_backend.load(sample_domain.flexo_id)) 25 25 assert loaded.description == "UPDATED DESC" 26 26 27 27 28 28 def test_delete_removes_entity(local_backend, sample_domain): 29 local_backend.save(sample_domain )29 local_backend.save(sample_domain.to_dict()) 30 30 local_backend.delete(sample_domain.flexo_id) 31 31 … … 35 35 36 36 def test_clear_removes_all(local_backend, sample_domain): 37 local_backend.save(sample_domain )37 local_backend.save(sample_domain.to_dict()) 38 38 local_backend.clear() 39 39 -
tests/test_json_file_backend.py
r54941b4 r3389960 22 22 dom2 = make_domain("PY_STRINGS") 23 23 24 backend.save(dom1 )25 backend.save(dom2 )24 backend.save(dom1.to_dict()) 25 backend.save(dom2.to_dict()) 26 26 backend.flush_to_file() 27 27 … … 29 29 backend2 = JsonFileBackend(Domain, path) 30 30 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) 34 34 assert ids == ["PY_ARITHM", "PY_STRINGS"] -
tests/test_sqlite_backend.py
r54941b4 r3389960 4 4 5 5 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): 6 def test_sqlite_roundtrip(tmp_path, sample_domain): 17 7 db_path = tmp_path / "domains.db" 18 8 conn = sqlite3.connect(db_path) … … 21 11 backend = SQLiteEntityBackend(Domain, conn, table_name="domains") 22 12 23 dom = make_domain() 24 backend.save(dom) 13 backend.save(sample_domain.to_dict()) 25 14 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() 28 17 29 18 all_loaded = backend.load_all() 30 19 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.
