Browse Source

[tests] fix tests for previous commit

Maxime Alves LIRMM@home 4 years ago
parent
commit
dc74902cdf
4 changed files with 41 additions and 8 deletions
  1. 1
    1
      db/pyheatpump.sql
  2. 7
    2
      db/test_variable_values.sql
  3. 3
    2
      tests/test_heatpump.py
  4. 30
    3
      tests/test_variable_values.py

+ 1
- 1
db/pyheatpump.sql View File

34
 INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
34
 INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
35
   'A', 'Analog', 'float', 1, 1250);
35
   'A', 'Analog', 'float', 1, 1250);
36
 INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
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
 INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
38
 INSERT INTO var_type (slabel, label, type, start_address, end_address) VALUES (
39
   'D', 'Digital', 'bool', 1, 1000);
39
   'D', 'Digital', 'bool', 1, 1000);
40
 
40
 

+ 7
- 2
db/test_variable_values.sql View File

1
 INSERT INTO var_value (type, address, value, time) VALUES
1
 INSERT INTO var_value (type, address, value, time) VALUES
2
 ('A', 10, 42, strftime('%s', 'now')),
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
 ('A', 10, 0, strftime('%s', datetime('now', '-2 days'))),
10
 ('A', 10, 0, strftime('%s', datetime('now', '-2 days'))),
6
 ('I', 5010, 42, strftime('%s',  datetime('now'))),
11
 ('I', 5010, 42, strftime('%s',  datetime('now'))),
7
 ('I', 5011, 24, strftime('%s',  datetime('now'))),
12
 ('I', 5011, 24, strftime('%s',  datetime('now'))),

+ 3
- 2
tests/test_heatpump.py View File

19
     assert isinstance(d_resp, dict)
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
     c = TestClient(app)
23
     c = TestClient(app)
24
     r = c.get('/')
24
     r = c.get('/')
25
     assert r.status_code == 200
25
     assert r.status_code == 200
29
 
29
 
30
     d_resp = json.loads(resp)
30
     d_resp = json.loads(resp)
31
     assert isinstance(d_resp, dict)
31
     assert isinstance(d_resp, dict)
32
+    print(d_resp)
32
 
33
 
33
     assert 'macAddress' in d_resp.keys()
34
     assert 'macAddress' in d_resp.keys()
34
     assert isinstance(d_resp['macAddress'], str)
35
     assert isinstance(d_resp['macAddress'], str)
40
     assert isinstance(d_resp['Integer'], dict)
41
     assert isinstance(d_resp['Integer'], dict)
41
     int_keys = list(map(int, d_resp['Integer'].keys()))
42
     int_keys = list(map(int, d_resp['Integer'].keys()))
42
     assert min(int_keys) == 1
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 View File

14
     assert r.status_code == 200
14
     assert r.status_code == 200
15
 
15
 
16
     d_resp = r.content.decode()
16
     d_resp = r.content.decode()
17
-    assert int(d_resp) == 42
17
+    assert float(d_resp) == 4.2
18
 
18
 
19
     try:
19
     try:
20
         r = c.get('/X/10')
20
         r = c.get('/X/10')
21
     except HTTPException as e:
21
     except HTTPException as e:
22
         assert e.status_code == 404
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
     r = c.get('/A/10/{}'.format(
44
     r = c.get('/A/10/{}'.format(
25
         (datetime.now() - timedelta(days=1)).isoformat()
45
         (datetime.now() - timedelta(days=1)).isoformat()
26
     ))
46
     ))
27
     d_resp = r.content.decode()
47
     d_resp = r.content.decode()
28
-    assert int(d_resp) == 20
48
+    assert float(d_resp) == 0
29
 
49
 
30
     r = c.get('/A/10/{}'.format(
50
     r = c.get('/A/10/{}'.format(
31
         (datetime.now() - timedelta(days=2)).isoformat()
51
         (datetime.now() - timedelta(days=2)).isoformat()
32
     ))
52
     ))
33
     d_resp = r.content.decode()
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
     r = c.get('/I/5010')
63
     r = c.get('/I/5010')
37
     d_resp = r.content.decode()
64
     d_resp = r.content.decode()

Loading…
Cancel
Save