pyHeatpump/tests/test_variable.py
Maxime Alves LIRMM@home e45a344428 [tests] update tests
2020-07-31 22:51:21 +02:00

51 lines
1.3 KiB
Python

#!/usr/bin/env python3
import pytest
from starlette.authentication import UnauthenticatedUser
from starlette.testclient import TestClient
from unittest.mock import patch, MagicMock
from pprint import pprint
import json
from tempfile import mkstemp
from configparser import ConfigParser
import os
import sys
from pyheatpump.conf import config
from pyheatpump.db import initialize, connect
from pyheatpump.variables import app, get_variables, set_variables, ROUTES
@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)
yield
os.unlink(tmpdb)
def test_get_(set_test_db):
c = TestClient(app)
r = c.get('/')
assert r.status_code == 200
d_resp = json.loads(r.content.decode())
pprint(d_resp)
assert 'A' in d_resp.keys()
assert '10' in d_resp['A'].keys()
assert len(d_resp['A'].keys()) == 4
assert len(d_resp['I'].keys()) == 4
assert len(d_resp['D'].keys()) == 4
@pytest.mark.skip
def test_set_(set_test_db):
c = TestClient(app)
r = c.post('/')
assert r.status_code == 200