-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.py
More file actions
52 lines (39 loc) · 1.82 KB
/
Copy pathtest_main.py
File metadata and controls
52 lines (39 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pytest
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_celsius_to_fahrenheit():
response = client.get("/celsius-to-fahrenheit?value=0")
assert response.status_code == 200
assert response.json()["output"] == pytest.approx(32)
response = client.get("/celsius-to-fahrenheit?value=100")
assert response.status_code == 200
assert response.json()["output"] == pytest.approx(212)
def test_fahrenheit_to_celsius():
response = client.get("/fahrenheit-to-celsius?value=32")
assert response.status_code == 200
assert response.json()["output"] == pytest.approx(0)
response = client.get("/fahrenheit-to-celsius?value=212")
assert response.status_code == 200
assert response.json()["output"] == pytest.approx(100)
def test_celsius_to_kelvin():
response = client.get("/celsius-to-kelvin?value=0")
assert response.status_code == 200
assert response.json()["output"] == pytest.approx(273.15)
response = client.get("/celsius-to-kelvin?value=100")
assert response.status_code == 200
assert response.json()["output"] == pytest.approx(373.15)
def test_kelvin_to_celsius():
response = client.get("/kelvin-to-celsius?value=273.15")
assert response.status_code == 200
assert response.json()["output"] == pytest.approx(0)
response = client.get("/kelvin-to-celsius?value=373.15")
assert response.status_code == 200
assert response.json()["output"] == pytest.approx(100)
def test_fahrenheit_to_kelvin():
response = client.get("/fahrenheit-to-kelvin?value=32")
assert response.status_code == 200
assert response.json()["output"] == pytest.approx(273.15)
response = client.get("/fahrenheit-to-kelvin?value=212")
assert response.status_code == 200
assert response.json()["output"] == pytest.approx(373.15)