123456789101112131415161718192021222324252627282930313233343536373839 |
- #!/usr/bin/env python3
- import pytest
- from starlette.authentication import UnauthenticatedUser
- from starlette.testclient import TestClient
- from pyheatpump.conf import app, config, default_config, CONFIG_FILES, get_config, set_config, config_route, ROUTES
- from pyheatpump.db import initialize, connect
- from unittest.mock import patch, MagicMock
- from pprint import pprint
- import json
- from tempfile import mkstemp
- from configparser import ConfigParser
- import os
-
- @pytest.fixture(scope='module')
- def set_test_db():
- _, tmpdb = mkstemp(suffix='.db', dir=os.getcwd(), )
- print(f'Will store database in {tmpdb}')
- config['heatpump']['database'] = tmpdb
- if not initialize(os.path.join(os.getcwd(), 'db/pyheatpump.sql')):
- sys.exit(-1)
-
- if not initialize(os.path.join(os.getcwd(), 'db/test_variables.sql')):
- sys.exit(-1)
-
- if not initialize(os.path.join(os.getcwd(), 'db/test_variable_values.sql')):
- sys.exit(-1)
-
- yield
-
- def test_get_(set_test_db):
- c = TestClient(app)
- r = c.get('/')
- assert r.status_code == 200
-
- resp = r.content.decode()
- assert type(resp) == str
-
- d_resp = json.loads(resp)
- assert type(d_resp) == dict
|