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_variable_values.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python3
  2. import pytest
  3. from starlette.exceptions import HTTPException
  4. from starlette.testclient import TestClient
  5. from datetime import datetime, timedelta
  6. from pyheatpump.variables import app, get_variables, set_variables, ROUTES
  7. from pyheatpump.variable_values import app, get_variable_value, set_variable_value, ROUTES
  8. def test_get_type_address(set_test_db):
  9. c = TestClient(app)
  10. r = c.get('/A/10')
  11. assert r.status_code == 200
  12. d_resp = r.content.decode()
  13. assert float(d_resp) == 4.2
  14. try:
  15. r = c.get('/X/10')
  16. except HTTPException as e:
  17. assert e.status_code == 404
  18. try:
  19. r = c.get('/A/11')
  20. d_resp = r.content.decode()
  21. assert float(d_resp) == -0.6
  22. r = c.get('/A/12')
  23. d_resp = r.content.decode()
  24. assert float(d_resp) == 3200.0
  25. r = c.get('/A/14')
  26. d_resp = r.content.decode()
  27. assert float(d_resp) == -2353.6
  28. """
  29. r = c.get('/A/10/{}'.format(
  30. (datetime.now() - timedelta(days=1)).isoformat()
  31. ))
  32. d_resp = r.content.decode()
  33. assert float(d_resp) == 4.2
  34. r = c.get('/A/17/{}'.format(
  35. (datetime.now() - timedelta(days=1)).isoformat()
  36. ))
  37. d_resp = r.content.decode()
  38. assert float(d_resp) == -2953.6
  39. r = c.get('/A/10/{}'.format(
  40. (datetime.now() - timedelta(days=2)).isoformat()
  41. ))
  42. d_resp = r.content.decode()
  43. assert float(d_resp) == 4.2
  44. """
  45. r = c.get('/I/5010')
  46. d_resp = r.content.decode()
  47. assert int(d_resp) == 42
  48. r = c.get('/I/5011')
  49. d_resp = r.content.decode()
  50. assert int(d_resp) == 24
  51. """
  52. r = c.get('/I/5010/{}'.format(
  53. (datetime.now() - timedelta(hours=1)).isoformat()
  54. ))
  55. d_resp = r.content.decode()
  56. assert int(d_resp) == 42
  57. r = c.get('/I/5010/{}'.format(
  58. (datetime.now() - timedelta(hours=2)).isoformat()
  59. ))
  60. d_resp = r.content.decode()
  61. assert int(d_resp) == 42
  62. """
  63. r = c.get('/D/10')
  64. d_resp = r.content.decode()
  65. assert d_resp == '1'
  66. r = c.get('/D/11')
  67. d_resp = r.content.decode()
  68. assert d_resp == '1'
  69. r = c.get('/D/12')
  70. d_resp = r.content.decode()
  71. assert d_resp == '0'
  72. except AssertionError as exc:
  73. print(d_resp)
  74. raise exc
  75. @pytest.mark.skip
  76. def test_set_(set_test_db):
  77. c = TestClient(app)
  78. r = c.post('/')
  79. assert r.status_code == 200