#!/usr/bin/env python3 import pytest from starlette.testclient import TestClient from unittest.mock import patch, MagicMock import json from pyheatpump.variable_types import app, get_variable_types, set_variable_types, ROUTES def test_get_(set_test_db): c = TestClient(app) r = c.get('/') assert r.status_code == 200 class RequestMock(MagicMock): def __get__(self, key): if key == 'method': return 'GET' @pytest.mark.asyncio async def test_get_variable_types(set_test_db): resp = await get_variable_types(RequestMock()) assert resp.status_code == 200 d_resp = json.loads(resp.body.decode()) assert 'Analog' in d_resp.keys() assert type(d_resp['Analog']) == dict assert 'Integer' in d_resp.keys() assert type(d_resp['Integer']) == dict assert 'Digital' in d_resp.keys() assert type(d_resp['Digital']) == dict @pytest.mark.skip def test_set_variable_types(set_test_db): c = TestClient(app) r = c.post('/', json=json.dumps({ 'Analog': { 'start_address': 42, 'end_address': 420, } })) assert r.status_code == 200 r = c.get('/') d_resp = json.loads(r.content.decode()) assert d_resp['Analog']['start_address'] == 42 assert d_resp['Analog']['end_address'] == 420