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_heatpump.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. import pytest
  3. from starlette.authentication import UnauthenticatedUser
  4. from starlette.testclient import TestClient
  5. from pyheatpump.conf import app, config, default_config, CONFIG_FILES, get_config, set_config, config_route, ROUTES
  6. from pyheatpump.db import initialize, connect
  7. from unittest.mock import patch, MagicMock
  8. from pprint import pprint
  9. import json
  10. from tempfile import mkstemp
  11. from configparser import ConfigParser
  12. import os
  13. @pytest.fixture(scope='module')
  14. def set_test_db():
  15. _, tmpdb = mkstemp(suffix='.db', dir=os.getcwd(), )
  16. print(f'Will store database in {tmpdb}')
  17. config['heatpump']['database'] = tmpdb
  18. if not initialize(os.path.join(os.getcwd(), 'db/pyheatpump.sql')):
  19. sys.exit(-1)
  20. if not initialize(os.path.join(os.getcwd(), 'db/test_variables.sql')):
  21. sys.exit(-1)
  22. if not initialize(os.path.join(os.getcwd(), 'db/test_variable_values.sql')):
  23. sys.exit(-1)
  24. yield
  25. def test_get_(set_test_db):
  26. c = TestClient(app)
  27. r = c.get('/')
  28. assert r.status_code == 200
  29. resp = r.content.decode()
  30. assert type(resp) == str
  31. d_resp = json.loads(resp)
  32. assert type(d_resp) == dict