Sfoglia il codice sorgente

[tests] fix tests for previous commit

Maxime Alves LIRMM@home 4 anni fa
parent
commit
dc74902cdf

+ 1
- 1
db/pyheatpump.sql Vedi File

@@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS var_value (
34 34
 INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
35 35
   'A', 'Analog', 'float', 1, 1250);
36 36
 INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
37
-  'I', 'Integer', 'int', 5002, 6252;
37
+  'I', 'Integer', 'int', 5002, 6252);
38 38
 INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
39 39
   'D', 'Digital', 'bool', 1, 1000);
40 40
 

+ 7
- 2
db/test_variable_values.sql Vedi File

@@ -1,7 +1,12 @@
1 1
 INSERT INTO var_value (type, address, value, time) VALUES
2 2
 ('A', 10, 42, strftime('%s', 'now')),
3
-('A', 11, 24, strftime('%s', datetime('now', '-1 hours'))),
4
-('A', 10, 20, strftime('%s', datetime('now', '-1 days'))),
3
+('A', 11, 65530, strftime('%s', 'now')),
4
+('A', 12, 32000, strftime('%s', 'now')),
5
+('A', 13, 4200, strftime('%s', 'now')),
6
+('A', 14, 42000, strftime('%s', 'now')),
7
+('A', 15, 10024, strftime('%s', 'now')),
8
+('A', 16, 24000, strftime('%s', datetime('now', '-1 hours'))),
9
+('A', 17, 36000, strftime('%s', datetime('now', '-1 days'))),
5 10
 ('A', 10, 0, strftime('%s', datetime('now', '-2 days'))),
6 11
 ('I', 5010, 42, strftime('%s',  datetime('now'))),
7 12
 ('I', 5011, 24, strftime('%s',  datetime('now'))),

+ 3
- 2
tests/test_heatpump.py Vedi File

@@ -19,7 +19,7 @@ def test_get_(set_test_db):
19 19
     assert isinstance(d_resp, dict)
20 20
 
21 21
 
22
-def test_dict(set_db_values):
22
+def test_dict(set_test_db):
23 23
     c = TestClient(app)
24 24
     r = c.get('/')
25 25
     assert r.status_code == 200
@@ -29,6 +29,7 @@ def test_dict(set_db_values):
29 29
 
30 30
     d_resp = json.loads(resp)
31 31
     assert isinstance(d_resp, dict)
32
+    print(d_resp)
32 33
 
33 34
     assert 'macAddress' in d_resp.keys()
34 35
     assert isinstance(d_resp['macAddress'], str)
@@ -40,5 +41,5 @@ def test_dict(set_db_values):
40 41
     assert isinstance(d_resp['Integer'], dict)
41 42
     int_keys = list(map(int, d_resp['Integer'].keys()))
42 43
     assert min(int_keys) == 1
43
-    assert max(int_keys) == 1250
44
+    assert max(int_keys) == 2
44 45
 

+ 30
- 3
tests/test_variable_values.py Vedi File

@@ -14,24 +14,51 @@ def test_get_type_address(set_test_db):
14 14
     assert r.status_code == 200
15 15
 
16 16
     d_resp = r.content.decode()
17
-    assert int(d_resp) == 42
17
+    assert float(d_resp) == 4.2
18 18
 
19 19
     try:
20 20
         r = c.get('/X/10')
21 21
     except HTTPException as e:
22 22
         assert e.status_code == 404
23 23
 
24
+    r = c.get('/A/11')
25
+    d_resp = r.content.decode()
26
+    assert float(d_resp) == -0.6
27
+
28
+
29
+    r = c.get('/A/12')
30
+    d_resp = r.content.decode()
31
+    assert float(d_resp) == 3200.0
32
+
33
+
34
+    r = c.get('/A/14')
35
+    d_resp = r.content.decode()
36
+    assert float(d_resp) == -2353.6
37
+
38
+
39
+    r = c.get('/A/17')
40
+    d_resp = r.content.decode()
41
+    assert float(d_resp) == -2953.6
42
+
43
+
24 44
     r = c.get('/A/10/{}'.format(
25 45
         (datetime.now() - timedelta(days=1)).isoformat()
26 46
     ))
27 47
     d_resp = r.content.decode()
28
-    assert int(d_resp) == 20
48
+    assert float(d_resp) == 0
29 49
 
30 50
     r = c.get('/A/10/{}'.format(
31 51
         (datetime.now() - timedelta(days=2)).isoformat()
32 52
     ))
33 53
     d_resp = r.content.decode()
34
-    assert int(d_resp) == 0
54
+    assert float(d_resp) == 0
55
+
56
+    r = c.get('/A/10/{}'.format(
57
+        (datetime.now() - timedelta(days=2)).isoformat()
58
+    ))
59
+    d_resp = r.content.decode()
60
+    assert float(d_resp) == 0
61
+
35 62
 
36 63
     r = c.get('/I/5010')
37 64
     d_resp = r.content.decode()

Loading…
Annulla
Salva