#!/usr/bin/env python3 import pytest from starlette.exceptions import HTTPException from starlette.testclient import TestClient from datetime import datetime, timedelta from pyheatpump.variables import app, get_variables, set_variables, ROUTES from pyheatpump.variable_values import app, get_variable_value, set_variable_value, ROUTES def test_get_type_address(set_test_db): c = TestClient(app) r = c.get('/A/10') assert r.status_code == 200 d_resp = r.content.decode() assert int(d_resp) == 42 try: r = c.get('/X/10') except HTTPException as e: assert e.status_code == 404 r = c.get('/A/10/{}'.format( (datetime.now() - timedelta(days=1)).isoformat() )) d_resp = r.content.decode() assert int(d_resp) == 20 r = c.get('/A/10/{}'.format( (datetime.now() - timedelta(days=2)).isoformat() )) d_resp = r.content.decode() assert int(d_resp) == 0 r = c.get('/I/5010') d_resp = r.content.decode() assert int(d_resp) == 42 r = c.get('/I/5011') d_resp = r.content.decode() assert int(d_resp) == 24 r = c.get('/I/5010/{}'.format( (datetime.now() - timedelta(hours=1)).isoformat() )) d_resp = r.content.decode() assert int(d_resp) == 20 r = c.get('/I/5010/{}'.format( (datetime.now() - timedelta(hours=2)).isoformat() )) d_resp = r.content.decode() assert int(d_resp) == 0 @pytest.mark.skip def test_set_(set_test_db): c = TestClient(app) r = c.post('/') assert r.status_code == 200