Projet de remplacement du "RPiPasserelle" d'Otec.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

test_heatpump.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python3
  2. import pytest
  3. from starlette.testclient import TestClient
  4. import json
  5. from pyheatpump.heatpump import app
  6. def test_get_(set_test_db):
  7. c = TestClient(app)
  8. r = c.get('/')
  9. assert r.status_code == 200
  10. resp = r.content.decode()
  11. assert isinstance(resp, str)
  12. d_resp = json.loads(resp)
  13. assert isinstance(d_resp, dict)
  14. def test_dict(set_test_db):
  15. c = TestClient(app)
  16. r = c.get('/')
  17. assert r.status_code == 200
  18. resp = r.content.decode()
  19. assert isinstance(resp, str)
  20. print(resp)
  21. d_resp = json.loads(resp)
  22. assert isinstance(d_resp, dict)
  23. print(d_resp)
  24. assert 'macAddress' in d_resp.keys()
  25. assert isinstance(d_resp['macAddress'], str)
  26. assert 'Analog' in d_resp.keys()
  27. assert isinstance(d_resp['Analog'], dict)
  28. int_keys = list(map(int, d_resp['Analog'].keys()))
  29. assert min(int_keys) == 10
  30. assert max(int_keys) == 17
  31. assert d_resp['Analog']['10'] == 4.2
  32. assert d_resp['Analog']['17'] == -2953.6
  33. assert 'Digital' in d_resp.keys()
  34. assert isinstance(d_resp['Digital'], dict)
  35. int_keys = list(map(int, d_resp['Digital'].keys()))
  36. assert min(int_keys) == 10
  37. assert max(int_keys) == 14
  38. assert d_resp['Digital']['10'] == False
  39. assert d_resp['Digital']['14'] == True
  40. assert 'Integer' in d_resp.keys()
  41. assert isinstance(d_resp['Integer'], dict)
  42. int_keys = list(map(int, d_resp['Integer'].keys()))
  43. print(int_keys)
  44. assert min(int_keys) == 1
  45. assert max(int_keys) == 10
  46. assert d_resp['Integer']['1'] == 101
  47. assert d_resp['Integer']['10'] == 24