from fastapi.testclient import TestClient from restAPIServer import app client = TestClient(app) def test_convert_to_utf8(): response = client.post("/convert/utf8/", json={"unit_string": r"\metre"}) assert response.status_code == 200 assert response.json() == ["m"] def test_convert_to_latex(): response = client.post("/convert/latex/", json={"unit_string": r"\metre\tothe{2}"}) assert response.status_code == 200 assert response.json() == ['$$\\mathrm{m}^{2}$$'] # Adjust based on actual response structure def test_compare_units_equal(): response = client.post("/compare/units/", json={"unit_string1": r"\watt", "unit_string2": r"\joule\per\second"}) assert response.status_code == 200 assert response.json() == {'scale_factor': 1.0, 'base_unit': '\\kilogram\\metre\\tothe{2}\\second\\tothe{-3}'} # Example expected response def test_compare_units_not_equal(): response = client.post("/compare/units/", json={"unit_string1": r"\metre", "unit_string2": r"\second"}) assert response.status_code == 200 assert "error" in response.json() # Checking for error message def test_compare_units_not_equal_but_equal_WithCompleate(): response = client.post("/compare/units/", json={"unit_string1": r"\one", "unit_string2": r"\percent", }) assert response.status_code == 200 assert "error" in response.json() # Checking for error message response = client.post("/compare/units/", json={"unit_string1": r"\one", "unit_string2": r"\percent", "complete":True}) assert response.status_code == 200 assert response.json() == {'scale_factor': 0.01, 'base_unit': '\\one'} def test_invalid_unit(): response = client.post("/convert/utf8/", json={"unit_string": "not_a_unit"}) assert response.status_code == 500 # Assuming your API returns 500 for invalid units