Browse Source

[route][config] fix GET /mac

Maxime Alves LIRMM@home 3 years ago
parent
commit
e895baedbc
2 changed files with 17 additions and 5 deletions
  1. 4
    4
      pyheatpump/config.py
  2. 13
    1
      tests/test_config.py

+ 4
- 4
pyheatpump/config.py View File

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

+ 13
- 1
tests/test_config.py View File

@@ -81,12 +81,24 @@ def test_set_config(tmpconf):
81 81
 
82 82
 
83 83
 def test_mac_address(testdir, tmpconf):
84
+    c = TestClient(app)
85
+    _, tmpconf = mkstemp()
86
+    CONFIG_FILES.append(tmpconf)
87
+
84 88
     mac_address = mac_address_init()
85 89
     assert type(get_config_dict()) == dict
86
-    d_config =get_config_dict()
90
+    d_config = get_config_dict()
87 91
 
88 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 103
 def test_last_update(testdir, tmpconf):
92 104
     c = TestClient(app)

Loading…
Cancel
Save