2018-11-18 15:40:10 +01:00
|
|
|
import asyncio
|
|
|
|
from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loop
|
2019-01-05 20:43:48 +01:00
|
|
|
from cbpi.craftbeerpi import CraftBeerPi
|
2018-11-18 15:40:10 +01:00
|
|
|
|
|
|
|
|
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-02 21:20:44 +01:00
|
|
|
@unittest_run_loop
|
|
|
|
async def test_heater(self):
|
|
|
|
resp = await self.client.get("/kettle/1/heater/on")
|
|
|
|
assert resp.status == 204
|
|
|
|
|
|
|
|
resp = await self.client.get("/kettle/1/heater/off")
|
|
|
|
assert resp.status == 204
|
|
|
|
|
|
|
|
@unittest_run_loop
|
|
|
|
async def test_agitator(self):
|
|
|
|
resp = await self.client.get("/kettle/1/agitator/on")
|
|
|
|
assert resp.status == 204
|
|
|
|
|
|
|
|
resp = await self.client.get("/kettle/1/agitator/off")
|
|
|
|
assert resp.status == 204
|
|
|
|
|
|
|
|
@unittest_run_loop
|
|
|
|
async def test_temp(self):
|
|
|
|
resp = await self.client.get("/kettle/1/temp")
|
2019-01-28 22:21:31 +01:00
|
|
|
assert resp.status == 204
|
2019-01-02 21:20:44 +01:00
|
|
|
|
|
|
|
resp = await self.client.get("/kettle/1/targettemp")
|
|
|
|
assert resp.status == 200
|
|
|
|
|
|
|
|
@unittest_run_loop
|
|
|
|
async def test_automatic(self):
|
2019-01-28 22:21:31 +01:00
|
|
|
resp = await self.client.post("/kettle/1/automatic")
|
2019-01-02 21:20:44 +01:00
|
|
|
assert resp.status == 204
|
|
|
|
|
|
|
|
|
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()
|
2018-12-03 22:16:03 +01:00
|
|
|
|
2019-07-27 21:08:19 +02:00
|
|
|
sensor_id = m["id"]
|
|
|
|
print("KETTLE", m["id"], m)
|
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
|
|
|
|
|
|
|
|