"""Reference loader: read the (single-sheet) master via streaming, skip a title banner above the headers, and not choke on a complex workbook. Multi-sheet selection is via the explicit `sheet=` arg (a picker is a future enhancement); the default is the first sheet.""" import io import openpyxl from app.refdata import load_reference_xlsx def _wb_bytes(): wb = openpyxl.Workbook() master = wb.active master.title = "Master" master.append(["Client master — do not edit"]) # title banner above the headers master.append(["Sr. No.", "Customer Name", "Partner", "Industry"]) master.append([1, "Acme Foods Limited", "Asha", "FMCG"]) master.append([2, "Zentron Robotics Inc", "Ben", "Robotics"]) extra = wb.create_sheet("Extra") extra.append(["junk", "data"]) buf = io.BytesIO() wb.save(buf) return buf.getvalue() def test_loads_first_sheet_and_skips_title_banner(): ref = load_reference_xlsx(_wb_bytes(), "master") assert ref["columns"][:2] == ["Sr. No.", "Customer Name"] # first sheet, banner row skipped assert len(ref["rows"]) == 2 assert ref["rows"][0]["Customer Name"] == "Acme Foods Limited" assert ref["rows"][0]["Partner"] == "Asha" def test_explicit_sheet_overrides_default(): ref = load_reference_xlsx(_wb_bytes(), "master", sheet="Extra") assert ref["columns"] == ["junk", "data"]