Browse Source

[tests][variables] fixed some loops and routes

Maxime Alves LIRMM@home 3 years ago
parent
commit
e4b9b43ddd

+ 6
- 6
pyheatpump/models/variable.py View File

@@ -55,15 +55,15 @@ class Variable(RowClass):
55 55
 
56 56
     @staticmethod
57 57
     def getall_of_type(type: VariableType) -> dict:
58
-        return dict([
59
-            (row['address'], Variable(**dict(row)))
58
+        return {
59
+            row['address']: Variable(**dict(row))
60 60
             for row in sql(
61 61
             """SELECT * FROM variable
62 62
             WHERE type = '{}'
63 63
                 AND address >= {}
64 64
                 AND address <= {}""".format(
65 65
             type, type.start_address, type.end_address))
66
-        ])
66
+       }
67 67
 
68 68
 
69 69
     @staticmethod
@@ -77,8 +77,8 @@ class Variable(RowClass):
77 77
         cast_fct = floatcast if type.slabel == 'A' else lambda x: x
78 78
 
79 79
         #offset = 10000 if (type.slabel == 'D') else 0
80
-        return dict([
81
-            (row['address'], cast_fct(row['value']))
80
+        return {
81
+            row['address']: cast_fct(row['value'])
82 82
             for row in sql(
83 83
             """SELECT var.address as address, val.value
84 84
             FROM variable var
@@ -92,7 +92,7 @@ class Variable(RowClass):
92 92
                 AND var.address <= {}
93 93
                 AND var.last_update > {}""".format(
94 94
             type, type.start_address, type.end_address, since))
95
-        ])
95
+        }
96 96
 
97 97
 
98 98
 

+ 4
- 3
pyheatpump/models/variable_type.py View File

@@ -106,9 +106,10 @@ class VariableType(RowClass):
106 106
 
107 107
     @staticmethod
108 108
     def getall():
109
-        return dict([
110
-            (row['label'], VariableType(**dict(row)))
111
-            for row in sql('SELECT * FROM var_type') ])
109
+        return {
110
+            row['label']: VariableType(**dict(row))
111
+            for row in sql('SELECT * FROM var_type')
112
+        }
112 113
 
113 114
     @staticmethod
114 115
     def get(slabel: str):

+ 9
- 8
pyheatpump/variables.py View File

@@ -14,15 +14,16 @@ from pyheatpump.models.variable import Variable
14 14
 
15 15
 
16 16
 async def get_variables(request):
17
-    return JSONResponse(dict([
18
-        (key, dict(
19
-            [
20
-                (add, var.__dict__)
17
+    def wo_type(d):
18
+        d.pop('type')
19
+        return d
20
+
21
+    return JSONResponse({
22
+        key: {
23
+            add: wo_type(var.__dict__)
21 24
                 for add, var in var_type.items()
22
-            ])
23
-        )
24
-        for key, var_type in Variable.getall().items()
25
-    ]))
25
+        } for key, var_type in Variable.getall().items()
26
+    })
26 27
 
27 28
 
28 29
 async def set_variables(request):

+ 2
- 2
tests/test_variable.py View File

@@ -35,8 +35,8 @@ def test_get_(set_test_db):
35 35
     r = c.get('/')
36 36
     assert r.status_code == 200
37 37
 
38
-    d_resp = json.loads(r.content.decode())
39
-    pprint(d_resp)
38
+    d_resp = r.json()
39
+    assert type(d_resp) is dict
40 40
     assert 'A' in d_resp.keys()
41 41
     assert '10' in d_resp['A'].keys()
42 42
     assert len(d_resp['A'].keys()) == 4

Loading…
Cancel
Save