2018-12-29 00:27:19 +01:00
|
|
|
import time
|
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
from aiohttp.test_utils import unittest_run_loop
|
|
|
|
from tests.cbpi_config_fixture import CraftBeerPiTestCase
|
2018-12-29 00:27:19 +01:00
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
class ConfigTestCase(CraftBeerPiTestCase):
|
2018-12-29 00:27:19 +01:00
|
|
|
|
|
|
|
async def test_get(self):
|
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
assert self.cbpi.config.get("steps_boil_temp", 1) == "99"
|
2018-12-29 00:27:19 +01:00
|
|
|
|
|
|
|
async def test_set_get(self):
|
2022-02-20 11:50:44 +01:00
|
|
|
value = 35
|
2018-12-29 00:27:19 +01:00
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
await self.cbpi.config.set("steps_cooldown_temp", value)
|
|
|
|
assert self.cbpi.config.get("steps_cooldown_temp", 1) == value
|
2018-12-29 00:27:19 +01:00
|
|
|
|
|
|
|
async def test_http_set(self):
|
2022-02-20 11:50:44 +01:00
|
|
|
value = "Some New Brewery Name"
|
|
|
|
key = "BREWERY_NAME"
|
2018-12-29 00:27:19 +01:00
|
|
|
|
2022-02-20 11:50:44 +01:00
|
|
|
resp = await self.client.request("PUT", "/config/%s/" % key, json={'value': value})
|
2018-12-29 00:27:19 +01:00
|
|
|
assert resp.status == 204
|
2022-02-20 11:50:44 +01:00
|
|
|
|
|
|
|
assert self.cbpi.config.get(key, -1) == value
|
2018-12-29 00:27:19 +01:00
|
|
|
|
|
|
|
async def test_http_get(self):
|
|
|
|
resp = await self.client.request("GET", "/config/")
|
|
|
|
assert resp.status == 200
|
2019-01-02 00:48:36 +01:00
|
|
|
|
2019-01-02 21:20:44 +01:00
|
|
|
async def test_get_default(self):
|
2022-02-20 11:50:44 +01:00
|
|
|
value = self.cbpi.config.get("HELLO_WORLD", "DefaultValue")
|
|
|
|
assert value == "DefaultValue"
|