From 2723cc8974d825faf393b4498cca49ac15254d18 Mon Sep 17 00:00:00 2001 From: Kawa Date: Fri, 10 Apr 2026 16:21:04 +0200 Subject: [PATCH] test(06-01): add failing test for icon inclusion in .intunewin export - test_intunewin_includes_icon: uploads PNG icon, asserts icon.png in staged files - test_intunewin_without_icon_succeeds: baseline no-icon export passes (already green) --- tests/test_packages.py | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/test_packages.py b/tests/test_packages.py index 3f4f6cb..6a39f1c 100644 --- a/tests/test_packages.py +++ b/tests/test_packages.py @@ -189,3 +189,58 @@ class TestCommandPreview: html = resp.text assert f"/printers/{printer.id}/icon" in html assert "icon-status" in html + + +# --------------------------------------------------------------------------- +# Icon inclusion in .intunewin export +# --------------------------------------------------------------------------- + + +class TestIntunewinIconInclusion: + def test_intunewin_includes_icon(self, client, setup_printer_with_driver, tmp_data_dir, monkeypatch): + """When a printer has an uploaded icon, icon.png must appear in the .intunewin staging directory.""" + import io as _io + import os + + from PIL import Image + + printer, _ = setup_printer_with_driver + + # Upload a 256x256 PNG icon for the printer + buf = _io.BytesIO() + Image.new("RGBA", (256, 256), color="red").save(buf, format="PNG") + buf.seek(0) + upload_resp = client.post( + f"/printers/{printer.id}/icon", + files={"file": ("icon.png", buf, "image/png")}, + ) + assert upload_resp.status_code == 200 + + # Monkeypatch build_intunewin to capture staged files and write a fake output + staged_files: list[str] = [] + + def fake_build(source_dir, setup_file, output_path): + staged_files.extend(os.listdir(source_dir)) + with open(output_path, "wb") as f: + f.write(b"FAKE") + + monkeypatch.setattr("imptune.api.packages.build_intunewin", fake_build) + + resp = client.get(f"/printers/{printer.id}/packages/intunewin") + assert resp.status_code == 200 + assert "icon.png" in staged_files + + def test_intunewin_without_icon_succeeds(self, client, setup_printer_with_driver, monkeypatch): + """When a printer has no icon, .intunewin export must succeed without error.""" + import os + + # Monkeypatch build_intunewin to write a fake output + def fake_build(source_dir, setup_file, output_path): + with open(output_path, "wb") as f: + f.write(b"FAKE") + + monkeypatch.setattr("imptune.api.packages.build_intunewin", fake_build) + + printer, _ = setup_printer_with_driver + resp = client.get(f"/printers/{printer.id}/packages/intunewin") + assert resp.status_code == 200