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.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python3
  2. import pytest
  3. from starlette.authentication import UnauthenticatedUser
  4. from starlette.testclient import TestClient
  5. from unittest.mock import patch, MagicMock
  6. from pprint import pprint
  7. import json
  8. from tempfile import mkstemp
  9. from configparser import ConfigParser
  10. import os
  11. import sys
  12. from pyheatpump.conf import config
  13. from pyheatpump.db import initialize, connect
  14. from pyheatpump.variables import app, get_variables, set_variables, ROUTES
  15. @pytest.fixture(scope='module')
  16. def set_test_db():
  17. _, tmpdb = mkstemp(suffix='.db', dir=os.getcwd(), )
  18. print(f'Will store database in {tmpdb}')
  19. config['heatpump']['database'] = tmpdb
  20. if not initialize(os.path.join(os.getcwd(), 'db/pyheatpump.sql')):
  21. sys.exit(-1)
  22. if not initialize(os.path.join(os.getcwd(), 'db/test_variables.sql')):
  23. sys.exit(-1)
  24. yield
  25. os.unlink(tmpdb)
  26. def test_get_(set_test_db):
  27. c = TestClient(app)
  28. r = c.get('/')
  29. assert r.status_code == 200
  30. d_resp = json.loads(r.content.decode())
  31. assert 'A' in d_resp.keys()
  32. assert 10 in d_resp['A']
  33. assert len(d_resp['A']) == 4
  34. assert len(d_resp['I']) == 4
  35. assert len(d_resp['D']) == 4
  36. @pytest.mark.skip
  37. def test_set_(set_test_db):
  38. c = TestClient(app)
  39. r = c.post('/')
  40. assert r.status_code == 200