Initial implementation of generic Excel-to-DB import tool
Supports .xls and .xlsx, Oracle and PostgreSQL via SQLAlchemy. Includes CLI (run/inspect/generate-config), YAML config, auto schema detection, and append/replace/upsert modes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from excel_import.config import ImportConfig
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_file(tmp_path: Path) -> Path:
|
||||
cfg = {
|
||||
"dsn": "postgresql+psycopg2://u:p@localhost/db",
|
||||
"sheets": [
|
||||
{
|
||||
"sheet": "Artikel",
|
||||
"header_row": 0,
|
||||
"target_table": "artikel",
|
||||
"mode": "replace",
|
||||
"columns": [
|
||||
{"source": "Artikelnummer", "target": "art_nr", "dtype": "VARCHAR(50)"},
|
||||
{"source": "Preis", "target": "preis"},
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
path = tmp_path / "config.yaml"
|
||||
path.write_text(yaml.dump(cfg))
|
||||
return path
|
||||
|
||||
|
||||
def test_load_from_yaml(config_file: Path):
|
||||
cfg = ImportConfig.from_yaml(config_file)
|
||||
assert cfg.dsn == "postgresql+psycopg2://u:p@localhost/db"
|
||||
assert len(cfg.sheets) == 1
|
||||
sheet = cfg.sheets[0]
|
||||
assert sheet.sheet == "Artikel"
|
||||
assert sheet.target_table == "artikel"
|
||||
assert sheet.mode == "replace"
|
||||
assert len(sheet.columns) == 2
|
||||
assert sheet.columns[0].dtype == "VARCHAR(50)"
|
||||
Reference in New Issue
Block a user