2018-12-31 00:22:00 +01:00
|
|
|
import aiohttp
|
2018-11-01 19:50:04 +01:00
|
|
|
from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loop
|
|
|
|
|
2018-11-01 21:25:42 +01:00
|
|
|
from core.craftbeerpi import CraftBeerPi
|
2018-11-01 19:50:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MyAppTestCase(AioHTTPTestCase):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_application(self):
|
|
|
|
self.cbpi = CraftBeerPi()
|
2018-12-31 00:22:00 +01:00
|
|
|
await self.cbpi.init_serivces()
|
2018-11-01 19:50:04 +01:00
|
|
|
return self.cbpi.app
|
|
|
|
|
|
|
|
|
|
|
|
@unittest_run_loop
|
|
|
|
async def test_example(self):
|
|
|
|
|
2018-12-31 00:22:00 +01:00
|
|
|
resp = await self.client.post(path="/login", data={"username": "cbpi", "password": "123"})
|
|
|
|
assert resp.status == 200
|
2018-11-16 20:35:59 +01:00
|
|
|
|
2018-12-31 00:22:00 +01:00
|
|
|
resp = await self.client.request("GET", "/actor/1/on")
|
2018-11-16 20:35:59 +01:00
|
|
|
assert resp.status == 204
|
|
|
|
i = await self.cbpi.actor.get_one(1)
|
|
|
|
assert i.instance.state is True
|
|
|
|
|
|
|
|
resp = await self.client.request("GET", "/actor/1/off")
|
|
|
|
assert resp.status == 204
|
|
|
|
i = await self.cbpi.actor.get_one(1)
|
|
|
|
assert i.instance.state is False
|
|
|
|
|
|
|
|
resp = await self.client.request("GET", "/actor/1/toggle")
|
|
|
|
|
|
|
|
assert resp.status == 204
|
|
|
|
i = await self.cbpi.actor.get_one(1)
|
|
|
|
assert i.instance.state is True
|
|
|
|
|
|
|
|
resp = await self.client.request("GET", "/actor/1/toggle")
|
|
|
|
assert resp.status == 204
|
|
|
|
i = await self.cbpi.actor.get_one(1)
|
|
|
|
assert i.instance.state is False
|
|
|
|
|
2018-11-01 19:50:04 +01:00
|
|
|
|
|
|
|
|