- Introduced tests for case creation commands, ensuring proper handling of UUIDs and payloads. - Added tests for v5 assignment functionality, validating employee identification and group assignment. - Implemented tests for remote recovery scenarios, including handling network failures and response validation. - Created tests for hardware label generation and validation, ensuring proper URL formatting and QR code generation. - Developed extensive tests for remote control functionality, covering connection isolation, command execution, and user permissions. - Added tests for workflow timer registration, ensuring correct handling of timer states and ownership validation.
27 lines
1.1 KiB
Python
27 lines
1.1 KiB
Python
"""Local QR generation for printable inventory labels. No asset writes."""
|
|
from urllib.parse import urlsplit, urlunsplit
|
|
|
|
import qrcode
|
|
from qrcode.image.svg import SvgPathImage
|
|
from fastapi import HTTPException
|
|
|
|
LABEL_SIZES = {'62x40': (62, 40), '62x29': (62, 29), '89x36': (89, 36)}
|
|
|
|
|
|
def hardware_label_url(base_url: str, hardware_id: int) -> str:
|
|
try:
|
|
parts = urlsplit(base_url.strip())
|
|
except ValueError as error:
|
|
raise HTTPException(400, "Hub-adressen er ugyldig") from error
|
|
if (parts.scheme not in {'http', 'https'} or not parts.hostname
|
|
or parts.username or parts.password or parts.query or parts.fragment):
|
|
raise HTTPException(400, 'Brug en http- eller https-adresse uden login, søgeparametre eller fragment.')
|
|
return urlunsplit((parts.scheme, parts.netloc, parts.path.rstrip('/') + f'/hardware/{hardware_id}', '', ''))
|
|
|
|
|
|
def hardware_label_qr(url: str) -> str:
|
|
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_M, border=4)
|
|
qr.add_data(url)
|
|
qr.make(fit=True)
|
|
return qr.make_image(image_factory=SvgPathImage).to_string().decode('utf-8')
|