2019-01-02 21:20:44 +01:00
|
|
|
import asyncio
|
2022-02-20 11:50:44 +01:00
|
|
|
from aiohttp.test_utils import unittest_run_loop
|
|
|
|
from tests.cbpi_config_fixture import CraftBeerPiTestCase
|
2019-01-02 21:20:44 +01:00
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
class StepTestCase(CraftBeerPiTestCase):
|
2019-01-02 21:20:44 +01:00
|
|
|
|
|
|
|
@unittest_run_loop
|
|
|
|
async def test_get(self):
|
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
@unittest_run_loop
|
|
|
|
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
|
2022-02-20 11:50:44 +01:00
|
|
|
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"]
|
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
# 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
|
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
# # 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:
|
2022-02-20 11:50:44 +01:00
|
|
|
pass
|