浏览代码

[route][config] fix GET /mac

Maxime Alves LIRMM@home 3 年前
父节点
当前提交
e895baedbc
共有 2 个文件被更改,包括 17 次插入5 次删除
  1. 4
    4
      pyheatpump/config.py
  2. 13
    1
      tests/test_config.py

+ 4
- 4
pyheatpump/config.py 查看文件

57
         config.write(conf_file)
57
         config.write(conf_file)
58
 
58
 
59
 
59
 
60
-def get_mac():
61
-    return get_config_dict()['heatpump', 'mac_address']
62
-
63
-
64
 def mac_address_init():
60
 def mac_address_init():
65
     from netifaces import gateways, ifaddresses, AF_INET, AF_LINK
61
     from netifaces import gateways, ifaddresses, AF_INET, AF_LINK
66
 
62
 
112
         return await set_config(request)
108
         return await set_config(request)
113
 
109
 
114
 
110
 
111
+def get_mac():
112
+    return config.get('heatpump','mac_address')
113
+
114
+
115
 async def mac_route(request, *args, **kwargs):
115
 async def mac_route(request, *args, **kwargs):
116
     if request['method'] == 'GET':
116
     if request['method'] == 'GET':
117
         return PlainTextResponse(get_mac())
117
         return PlainTextResponse(get_mac())

+ 13
- 1
tests/test_config.py 查看文件

81
 
81
 
82
 
82
 
83
 def test_mac_address(testdir, tmpconf):
83
 def test_mac_address(testdir, tmpconf):
84
+    c = TestClient(app)
85
+    _, tmpconf = mkstemp()
86
+    CONFIG_FILES.append(tmpconf)
87
+
84
     mac_address = mac_address_init()
88
     mac_address = mac_address_init()
85
     assert type(get_config_dict()) == dict
89
     assert type(get_config_dict()) == dict
86
-    d_config =get_config_dict()
90
+    d_config = get_config_dict()
87
 
91
 
88
     assert d_config['heatpump']['mac_address'] == mac_address
92
     assert d_config['heatpump']['mac_address'] == mac_address
89
 
93
 
94
+    resp = c.get('/mac')
95
+    assert resp.status_code  == 200
96
+    mac_address = resp.content.decode()
97
+
98
+    assert d_config['heatpump']['mac_address'] == mac_address
99
+
100
+
101
+
90
 
102
 
91
 def test_last_update(testdir, tmpconf):
103
 def test_last_update(testdir, tmpconf):
92
     c = TestClient(app)
104
     c = TestClient(app)

正在加载...
取消
保存