123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #!/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 float(d_resp) == 4.2
-
- try:
- r = c.get('/X/10')
- except HTTPException as e:
- assert e.status_code == 404
-
- try:
- r = c.get('/A/11')
- d_resp = r.content.decode()
- assert float(d_resp) == -0.6
-
-
- r = c.get('/A/12')
- d_resp = r.content.decode()
- assert float(d_resp) == 3200.0
-
-
- r = c.get('/A/14')
- d_resp = r.content.decode()
- assert float(d_resp) == -2353.6
-
-
-
- """
- r = c.get('/A/10/{}'.format(
- (datetime.now() - timedelta(days=1)).isoformat()
- ))
- d_resp = r.content.decode()
- assert float(d_resp) == 4.2
-
- r = c.get('/A/17/{}'.format(
- (datetime.now() - timedelta(days=1)).isoformat()
- ))
- d_resp = r.content.decode()
- assert float(d_resp) == -2953.6
-
-
- r = c.get('/A/10/{}'.format(
- (datetime.now() - timedelta(days=2)).isoformat()
- ))
- d_resp = r.content.decode()
- assert float(d_resp) == 4.2
- """
-
-
- 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) == 42
-
- r = c.get('/I/5010/{}'.format(
- (datetime.now() - timedelta(hours=2)).isoformat()
- ))
- d_resp = r.content.decode()
- assert int(d_resp) == 42
- """
-
- r = c.get('/D/10')
- d_resp = r.content.decode()
- assert d_resp == '1'
-
- r = c.get('/D/11')
- d_resp = r.content.decode()
- assert d_resp == '1'
-
- r = c.get('/D/12')
- d_resp = r.content.decode()
- assert d_resp == '0'
- except AssertionError as exc:
- print(d_resp)
- raise exc
-
-
-
- @pytest.mark.skip
- def test_set_(set_test_db):
- c = TestClient(app)
- r = c.post('/')
- assert r.status_code == 200
|