|
@@ -2,7 +2,7 @@
|
2
|
2
|
import pytest
|
3
|
3
|
from starlette.authentication import UnauthenticatedUser
|
4
|
4
|
from starlette.testclient import TestClient
|
5
|
|
-from pyheatpump.config import app, config, default_config, CONFIG_FILES, get_config, set_config, config_route, ROUTES
|
|
5
|
+from pyheatpump.config import app, config, default_config, CONFIG_FILES, get_config, set_config, config_route, ROUTES, mac_address_init, save_config
|
6
|
6
|
from unittest.mock import patch, MagicMock
|
7
|
7
|
from pprint import pprint
|
8
|
8
|
import json
|
|
@@ -10,16 +10,33 @@ from tempfile import mkstemp
|
10
|
10
|
from configparser import ConfigParser
|
11
|
11
|
import os
|
12
|
12
|
|
|
13
|
+@pytest.fixture
|
|
14
|
+def tmpconf(testdir):
|
|
15
|
+ tmp_conf_filepath = os.path.join(testdir.tmpdir, 'pyheatpump.ini')
|
|
16
|
+ config = ConfigParser(
|
|
17
|
+ default_section='heatpump')
|
|
18
|
+ config.read_dict(default_config)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+ with open(tmp_conf_filepath, 'w') as f:
|
|
22
|
+ f.write("[heatpump]\nmac_address = 'None'")
|
|
23
|
+ CONFIG_FILES = [tmp_conf_filepath]
|
|
24
|
+ config.read(filenames=CONFIG_FILES)
|
|
25
|
+
|
|
26
|
+ return config
|
|
27
|
+
|
13
|
28
|
def test_get_():
|
14
|
29
|
c = TestClient(app)
|
15
|
30
|
r = c.get('/')
|
16
|
31
|
assert r.status_code == 200
|
17
|
32
|
|
|
33
|
+
|
18
|
34
|
class RequestMock(MagicMock):
|
19
|
35
|
def __get__(self, key):
|
20
|
36
|
if key == 'method':
|
21
|
37
|
return 'GET'
|
22
|
38
|
|
|
39
|
+
|
23
|
40
|
@pytest.mark.asyncio
|
24
|
41
|
async def test_get_config():
|
25
|
42
|
resp = await get_config(RequestMock())
|
|
@@ -30,6 +47,7 @@ async def test_get_config():
|
30
|
47
|
for item in default_config[sect].keys():
|
31
|
48
|
assert item in d_resp[sect].keys()
|
32
|
49
|
|
|
50
|
+
|
33
|
51
|
def test_set_config():
|
34
|
52
|
c = TestClient(app)
|
35
|
53
|
_, tmpconf = mkstemp()
|
|
@@ -47,3 +65,13 @@ def test_set_config():
|
47
|
65
|
assert config.get('supervisor', 'scheme') == 'test'
|
48
|
66
|
|
49
|
67
|
os.unlink(tmpconf)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+def test_mac_address(testdir, tmpconf):
|
|
71
|
+ try:
|
|
72
|
+ assert tmpconf.get('heatpump', 'mac_address') is 'None'
|
|
73
|
+ mac_address = mac_address_init()
|
|
74
|
+ config_mac_address = tmpconf.get('heatpump', 'mac_address')
|
|
75
|
+ assert config_mac_address == mac_address
|
|
76
|
+ except Exception as e:
|
|
77
|
+ raise e
|