craftbeerpi4-pione/tests/test_kettle.py

59 lines
1.5 KiB
Python
Raw Normal View History

2018-11-18 15:40:10 +01:00
import asyncio
from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loop
from core.craftbeerpi import CraftBeerPi
2018-11-18 23:09:17 +01:00
class KettleTestCase(AioHTTPTestCase):
2018-11-18 15:40:10 +01:00
async def get_application(self):
self.cbpi = CraftBeerPi()
2019-01-01 15:35:35 +01:00
await self.cbpi.init_serivces()
2018-11-18 15:40:10 +01:00
return self.cbpi.app
@unittest_run_loop
2019-01-01 15:35:35 +01:00
async def test_get(self):
resp = await self.client.request("GET", "/kettle")
assert resp.status == 200
print(await resp.json())
2018-12-13 21:45:33 +01:00
2019-01-01 15:35:35 +01:00
@unittest_run_loop
2019-01-02 00:48:36 +01:00
async def test_crud(self):
2019-01-01 15:35:35 +01:00
data = {
"name": "Test",
"sensor": None,
"heater": "1",
"automatic": None,
"logic": "CustomKettleLogic",
"config": {
"test": "WOOHO"
},
"agitator": None,
"target_temp": None
}
2019-01-02 00:48:36 +01:00
# Add new sensor
2019-01-01 15:35:35 +01:00
resp = await self.client.post(path="/kettle/", json=data)
assert resp.status == 200
2018-12-13 21:45:33 +01:00
2019-01-02 00:48:36 +01:00
m = await resp.json()
sensor_id = m["id"]
2018-12-03 22:16:03 +01:00
2019-01-02 00:48:36 +01:00
# Get sensor
resp = await self.client.get(path="/kettle/%s" % sensor_id)
assert resp.status == 200
m2 = await resp.json()
sensor_id = m2["id"]
2018-12-03 22:16:03 +01:00
2019-01-02 00:48:36 +01:00
# Update Sensor
resp = await self.client.put(path="/kettle/%s" % sensor_id, json=m)
assert resp.status == 200
2018-12-03 22:16:03 +01:00
2019-01-02 00:48:36 +01:00
# # Delete Sensor
resp = await self.client.delete(path="/kettle/%s" % sensor_id)
assert resp.status == 204
2018-12-03 22:16:03 +01:00