Browse Source

[tests] tests de lib/shift_response et de heatpump/dict

Maxime Alves LIRMM@home 3 years ago
parent
commit
a22bb05084
4 changed files with 76 additions and 2 deletions
  1. BIN
      db/prod-b827ebbcab83-20201206.db
  2. 9
    0
      tests/conftest.py
  3. 28
    2
      tests/test_heatpump.py
  4. 39
    0
      tests/test_lib.py

BIN
db/prod-b827ebbcab83-20201206.db View File


+ 9
- 0
tests/conftest.py View File

@@ -1,5 +1,6 @@
1 1
 import os
2 2
 import pytest
3
+import shutil
3 4
 import sys
4 5
 from tempfile import mkstemp
5 6
 
@@ -25,6 +26,14 @@ def set_test_db():
25 26
     yield
26 27
 
27 28
 
29
+@pytest.fixture(scope="module")
30
+def set_db_values():
31
+    _, tmpdb = mkstemp(suffix='.db', dir=os.getcwd(), )
32
+    db_file = "./db/prod-b827ebbcab83-20201206.db"
33
+    shutil.copy(db_file, tmpdb)
34
+    config['heatpump']['database'] = tmpdb
35
+    yield
36
+
28 37
 
29 38
 @pytest.fixture
30 39
 def var_types():

+ 28
- 2
tests/test_heatpump.py View File

@@ -6,13 +6,39 @@ import json
6 6
 from pyheatpump.heatpump import app
7 7
 
8 8
 
9
+@pytest.mark.skip
9 10
 def test_get_(set_test_db):
10 11
     c = TestClient(app)
11 12
     r = c.get('/')
12 13
     assert r.status_code == 200
13 14
 
14 15
     resp = r.content.decode()
15
-    assert type(resp) == str
16
+    assert isinstance(resp, str)
16 17
 
17 18
     d_resp = json.loads(resp)
18
-    assert type(d_resp) == dict
19
+    assert isinstance(d_resp, dict)
20
+
21
+
22
+def test_dict(set_db_values):
23
+    c = TestClient(app)
24
+    r = c.get('/')
25
+    assert r.status_code == 200
26
+
27
+    resp = r.content.decode()
28
+    assert isinstance(resp, str)
29
+
30
+    d_resp = json.loads(resp)
31
+    assert isinstance(d_resp, dict)
32
+
33
+    assert 'macAddress' in d_resp.keys()
34
+    assert isinstance(d_resp['macAddress'], str)
35
+    assert 'Analog' in d_resp.keys()
36
+    assert isinstance(d_resp['Analog'], dict)
37
+    assert 'Digital' in d_resp.keys()
38
+    assert isinstance(d_resp['Digital'], dict)
39
+    assert 'Integer' in d_resp.keys()
40
+    assert isinstance(d_resp['Integer'], dict)
41
+    int_keys = list(map(int, d_resp['Integer'].keys()))
42
+    assert min(int_keys) == 1
43
+    assert max(int_keys) == 1250
44
+

+ 39
- 0
tests/test_lib.py View File

@@ -0,0 +1,39 @@
1
+#!/usr/bin/env python3
2
+import pytest
3
+
4
+from pyheatpump.lib import shift_response
5
+
6
+def test_shift_response():
7
+    heatpump_dict = {}
8
+    heatpump_dict['Analog'] = {
9
+        key: 0
10
+        for key in range(1, 1251)
11
+    }
12
+    heatpump_dict['Integer'] = {
13
+        key: 0
14
+        for key in range(5002, 6252 )
15
+    }
16
+    heatpump_dict['Digital'] = {
17
+        key: 0
18
+        for key in range(1, 1001)
19
+    }
20
+
21
+    assert isinstance(heatpump_dict, dict)
22
+    
23
+    shifted = shift_response(heatpump_dict)
24
+    assert isinstance(shifted, dict) 
25
+
26
+    assert 'Analog' in shifted.keys()
27
+    assert isinstance(shifted['Analog'], dict)
28
+
29
+    assert 'Digital' in shifted.keys()
30
+    assert isinstance(shifted['Digital'], dict)
31
+
32
+    assert 'Integer' in shifted.keys()
33
+    assert isinstance(shifted['Integer'], dict)
34
+    for k in shifted['Integer'].keys():
35
+        assert isinstance(k, str)
36
+
37
+    int_keys = list(map(int, shifted['Integer'].keys()))
38
+    assert min(int_keys) == 1
39
+    assert max(int_keys) == 1250

Loading…
Cancel
Save