Projet de remplacement du "RPiPasserelle" d'Otec.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_variable_types.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. import pytest
  3. from starlette.testclient import TestClient
  4. from unittest.mock import patch, MagicMock
  5. import json
  6. from pyheatpump.variable_types import app, get_variable_types, set_variable_types, ROUTES
  7. def test_get_(set_test_db):
  8. c = TestClient(app)
  9. r = c.get('/')
  10. assert r.status_code == 200
  11. class RequestMock(MagicMock):
  12. def __get__(self, key):
  13. if key == 'method':
  14. return 'GET'
  15. @pytest.mark.asyncio
  16. async def test_get_variable_types(set_test_db):
  17. resp = await get_variable_types(RequestMock())
  18. assert resp.status_code == 200
  19. d_resp = json.loads(resp.body.decode())
  20. assert 'Analog' in d_resp.keys()
  21. assert type(d_resp['Analog']) == dict
  22. assert 'Integer' in d_resp.keys()
  23. assert type(d_resp['Integer']) == dict
  24. assert 'Digital' in d_resp.keys()
  25. assert type(d_resp['Digital']) == dict
  26. @pytest.mark.skip
  27. def test_set_variable_types(set_test_db):
  28. c = TestClient(app)
  29. r = c.post('/', json=json.dumps({
  30. 'Analog': {
  31. 'start_address': 42,
  32. 'end_address': 420,
  33. }
  34. }))
  35. assert r.status_code == 200
  36. r = c.get('/')
  37. d_resp = json.loads(r.content.decode())
  38. assert d_resp['Analog']['start_address'] == 42
  39. assert d_resp['Analog']['end_address'] == 420