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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 unittest.mock import patch, MagicMock
  7. from pprint import pprint
  8. import json
  9. from tempfile import mkstemp
  10. from configparser import ConfigParser
  11. import os
  12. def test_get_():
  13. c = TestClient(app)
  14. r = c.get('/')
  15. assert r.status_code == 200
  16. class RequestMock(MagicMock):
  17. def __get__(self, key):
  18. if key == 'method':
  19. return 'GET'
  20. @pytest.mark.asyncio
  21. async def test_get_config():
  22. resp = await get_config(RequestMock())
  23. assert resp.status_code == 200
  24. d_resp = json.loads(resp.body.decode())
  25. for sect in default_config.keys():
  26. assert sect in d_resp.keys()
  27. for item in default_config[sect].keys():
  28. assert item in d_resp[sect].keys()
  29. def test_set_config():
  30. c = TestClient(app)
  31. _, tmpconf = mkstemp()
  32. CONFIG_FILES.insert(0, tmpconf)
  33. r = c.post('/', json=json.dumps({
  34. 'supervisor': {
  35. 'scheme':'test'
  36. }
  37. }))
  38. config = ConfigParser()
  39. config.read(filenames=[tmpconf])
  40. assert r.status_code == 200
  41. assert config.get('supervisor', 'scheme') == 'test'
  42. os.unlink(tmpconf)