Browse Source

[tests] update tests for last commit

Maxime Alves LIRMM@home 3 years ago
parent
commit
c07b7f8005
4 changed files with 28 additions and 7 deletions
  1. 1
    1
      db/test_variable_values.sql
  2. 7
    3
      db/test_variables.sql
  3. 1
    1
      tests/conftest.py
  4. 19
    2
      tests/test_heatpump.py

+ 1
- 1
db/test_variable_values.sql View File

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

+ 7
- 3
db/test_variables.sql View File

@@ -3,11 +3,15 @@ INSERT INTO variable (type, address, unit) VALUES
3 3
 ('A', 11, 'deg'),
4 4
 ('A', 12, 'deg'),
5 5
 ('A', 13, 'deg'),
6
+('A', 14, 'deg'),
7
+('A', 15, 'deg'),
8
+('A', 16, 'deg'),
9
+('A', 17, 'deg'),
10
+('I', 5002, 'deg'),
6 11
 ('I', 5010, 'deg'),
7 12
 ('I', 5011, 'deg'),
8
-('I', 5012, 'deg'),
9
-('I', 5013, 'deg'),
10 13
 ('D', 10, 'bit'),
11 14
 ('D', 11, 'bit'),
12 15
 ('D', 12, 'bit'),
13
-('D', 13, 'bit');
16
+('D', 13, 'bit'),
17
+('D', 14, 'bit');

+ 1
- 1
tests/conftest.py View File

@@ -25,7 +25,7 @@ def set_test_db():
25 25
 
26 26
     yield
27 27
 
28
-    os.unlink(tmpdb)
28
+    #os.unlink(tmpdb)
29 29
 
30 30
 
31 31
 @pytest.fixture(scope="module")

+ 19
- 2
tests/test_heatpump.py View File

@@ -6,7 +6,6 @@ import json
6 6
 from pyheatpump.heatpump import app
7 7
 
8 8
 
9
-@pytest.mark.skip
10 9
 def test_get_(set_test_db):
11 10
     c = TestClient(app)
12 11
     r = c.get('/')
@@ -27,6 +26,7 @@ def test_dict(set_test_db):
27 26
     resp = r.content.decode()
28 27
     assert isinstance(resp, str)
29 28
 
29
+    print(resp)
30 30
     d_resp = json.loads(resp)
31 31
     assert isinstance(d_resp, dict)
32 32
     print(d_resp)
@@ -35,11 +35,28 @@ def test_dict(set_test_db):
35 35
     assert isinstance(d_resp['macAddress'], str)
36 36
     assert 'Analog' in d_resp.keys()
37 37
     assert isinstance(d_resp['Analog'], dict)
38
+    int_keys = list(map(int, d_resp['Analog'].keys()))
39
+    assert min(int_keys) == 10
40
+    assert max(int_keys) == 17
41
+    assert d_resp['Analog']['10'] == 4.2
42
+    assert d_resp['Analog']['17'] == -2953.6
43
+
38 44
     assert 'Digital' in d_resp.keys()
39 45
     assert isinstance(d_resp['Digital'], dict)
46
+    int_keys = list(map(int, d_resp['Digital'].keys()))
47
+    assert min(int_keys) == 10
48
+    assert max(int_keys) == 14
49
+
50
+    assert d_resp['Digital']['10'] == False
51
+    assert d_resp['Digital']['14'] == True
52
+
40 53
     assert 'Integer' in d_resp.keys()
41 54
     assert isinstance(d_resp['Integer'], dict)
42 55
     int_keys = list(map(int, d_resp['Integer'].keys()))
56
+    print(int_keys)
43 57
     assert min(int_keys) == 1
44
-    assert max(int_keys) == 2
58
+    assert max(int_keys) == 10
59
+
60
+    assert d_resp['Integer']['1'] == 101
61
+    assert d_resp['Integer']['10'] == 24
45 62
 

Loading…
Cancel
Save