49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
"""Tests for admin panel — clear_all, reseed, and additive reseed."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from physcom.seed.transport_example import load_transport_seed
|
|
|
|
|
|
def test_clear_all_wipes_data(seeded_repo):
|
|
"""clear_all() should remove all rows from every table."""
|
|
repo = seeded_repo
|
|
assert len(repo.list_entities()) > 0
|
|
assert len(repo.list_domains()) > 0
|
|
|
|
repo.clear_all()
|
|
|
|
assert len(repo.list_entities()) == 0
|
|
assert len(repo.list_domains()) == 0
|
|
assert len(repo.list_dimensions()) == 0
|
|
assert sum(repo.count_combinations_by_status().values()) == 0
|
|
assert len(repo.list_pipeline_runs()) == 0
|
|
|
|
|
|
def test_reseed_after_clear_restores_data(seeded_repo):
|
|
"""Wipe then reseed should restore entity/domain counts."""
|
|
repo = seeded_repo
|
|
original_entities = len(repo.list_entities())
|
|
original_domains = len(repo.list_domains())
|
|
|
|
repo.clear_all()
|
|
assert len(repo.list_entities()) == 0
|
|
|
|
counts = load_transport_seed(repo)
|
|
assert len(repo.list_entities()) == original_entities
|
|
assert len(repo.list_domains()) == original_domains
|
|
assert counts["platforms"] + counts["actuators"] + counts["energy_storages"] == original_entities
|
|
|
|
|
|
def test_additive_reseed_no_duplicates(seeded_repo):
|
|
"""Running reseed on an already-seeded DB should not create duplicates."""
|
|
repo = seeded_repo
|
|
before = len(repo.list_entities())
|
|
|
|
counts = load_transport_seed(repo)
|
|
|
|
assert len(repo.list_entities()) == before
|
|
assert counts["platforms"] == 0
|
|
assert counts["actuators"] + counts["energy_storages"] == 0
|
|
assert counts["domains"] == 0
|