craftbeerpi4-pione/tests/test_step.py

50 lines
1.3 KiB
Python
Raw Normal View History

2019-01-02 21:20:44 +01:00
import asyncio
from aiohttp.test_utils import unittest_run_loop
from tests.cbpi_config_fixture import CraftBeerPiTestCase
2019-01-02 21:20:44 +01:00
class StepTestCase(CraftBeerPiTestCase):
2019-01-02 21:20:44 +01:00
async def test_get(self):
resp = await self.client.request("GET", "/step2")
2019-07-27 21:08:19 +02:00
print(resp)
2019-01-02 21:20:44 +01:00
assert resp.status == 200
async def test_crud(self):
data = {
"name": "Test",
"type": "CustomStepCBPi",
2019-07-27 21:08:19 +02:00
"config": {}
2019-01-02 21:20:44 +01:00
}
2019-07-27 21:08:19 +02:00
# Add new step
resp = await self.client.post(path="/step2/", json=data)
2019-01-02 21:20:44 +01:00
assert resp.status == 200
m = await resp.json()
2019-07-27 21:08:19 +02:00
print("Step", m)
2019-01-02 21:20:44 +01:00
sensor_id = m["id"]
# Update step
resp = await self.client.put(path="/step2/%s" % sensor_id, json=m)
2019-01-02 21:20:44 +01:00
assert resp.status == 200
# # Delete step
resp = await self.client.delete(path="/step2/%s" % sensor_id)
2019-01-02 21:20:44 +01:00
assert resp.status == 204
2019-01-04 09:29:09 +01:00
def create_wait_callback(self, topic):
future = self.cbpi.app.loop.create_future()
async def test(**kwargs):
print("GOON")
future.set_result("OK")
self.cbpi.bus.register(topic, test, once=True)
return future
async def wait(self, future):
done, pending = await asyncio.wait({future})
if future in done:
pass