diagram_ph/tests/test_diagram_api.py

45 lines
1.1 KiB
Python

import base64
import pytest
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_diagram_json_no_image():
body = {
'refrigerant': 'R290',
'pressure_range': {'min': 0.1, 'max': 10.0},
'format': 'json',
'include_isotherms': True,
'width': 800,
'height': 600,
'dpi': 100
}
r = client.post('/api/v1/diagrams/ph', json=body)
assert r.status_code == 200
j = r.json()
# image key should not be present for json-only
assert 'image' not in j
assert 'data' in j
def test_diagram_png_includes_image():
body = {
'refrigerant': 'R290',
'pressure_range': {'min': 0.1, 'max': 10.0},
'format': 'png',
'include_isotherms': True,
'width': 800,
'height': 600,
'dpi': 100
}
r = client.post('/api/v1/diagrams/ph', json=body)
assert r.status_code == 200
j = r.json()
assert 'image' in j
# Validate base64 decodes
decoded = base64.b64decode(j['image'])
assert len(decoded) > 10