add test where all the values get written to the db
This commit is contained in:
parent
30a9c3a77d
commit
bc55d5e5e9
|
@ -0,0 +1,50 @@
|
||||||
|
from plotly.offline import plot
|
||||||
|
from plotly.graph_objs import Scatter
|
||||||
|
import plotly.express as px
|
||||||
|
from collector.models import Time, Temperature, Humidity, Pressure
|
||||||
|
|
||||||
|
|
||||||
|
def temperature():
|
||||||
|
data = Temperature.objects.all()[30:]
|
||||||
|
x_axis = []
|
||||||
|
y_axis = []
|
||||||
|
for point in data:
|
||||||
|
print(point.value)
|
||||||
|
x_axis.append(point.value)
|
||||||
|
y_axis.append(point.time.value)
|
||||||
|
|
||||||
|
plot_div = plot([Scatter(x=x_axis , y=y_axis,
|
||||||
|
mode='lines', name='temperature',
|
||||||
|
opacity=0.8, marker_color='green')],
|
||||||
|
output_type='div')
|
||||||
|
return plot_div
|
||||||
|
|
||||||
|
|
||||||
|
def humidity():
|
||||||
|
data = Humidity.objects.all()[30:]
|
||||||
|
x_axis = []
|
||||||
|
y_axis = []
|
||||||
|
for point in data:
|
||||||
|
x_axis.append(point.value)
|
||||||
|
y_axis.append(point.time.value)
|
||||||
|
|
||||||
|
plot_div = plot([Scatter(x=x_axis , y=y_axis,
|
||||||
|
mode='lines', name='humidity',
|
||||||
|
opacity=0.8, marker_color='green')],
|
||||||
|
output_type='div')
|
||||||
|
return plot_div
|
||||||
|
|
||||||
|
|
||||||
|
def pressure():
|
||||||
|
data = Pressure.objects.all()[30:]
|
||||||
|
x_axis = []
|
||||||
|
y_axis = []
|
||||||
|
for point in data:
|
||||||
|
x_axis.append(point.value)
|
||||||
|
y_axis.append(point.time.value)
|
||||||
|
|
||||||
|
plot_div = plot([Scatter(x=x_axis , y=y_axis,
|
||||||
|
mode='lines', name='pressure',
|
||||||
|
opacity=0.8, marker_color='green')],
|
||||||
|
output_type='div')
|
||||||
|
return plot_div
|
|
@ -2,6 +2,7 @@ import datetime
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from collector import collector
|
from collector import collector
|
||||||
|
from collector.models import Temperature, Humidity, Pressure
|
||||||
|
|
||||||
pytestmark=pytest.mark.django_db
|
pytestmark=pytest.mark.django_db
|
||||||
|
|
||||||
|
@ -28,3 +29,27 @@ def test_pressure_collector(monkeypatch):
|
||||||
|
|
||||||
monkeypatch.setattr(collector.sense, 'get_pressure', mock_pressure)
|
monkeypatch.setattr(collector.sense, 'get_pressure', mock_pressure)
|
||||||
assert collector.get_pressure() == 1013.3
|
assert collector.get_pressure() == 1013.3
|
||||||
|
|
||||||
|
|
||||||
|
def test_values_to_db(monkeypatch):
|
||||||
|
def mock_temp():
|
||||||
|
return 25.345
|
||||||
|
|
||||||
|
monkeypatch.setattr(collector.sense, 'get_temperature', mock_temp)
|
||||||
|
|
||||||
|
def mock_humidity():
|
||||||
|
return 45.2356
|
||||||
|
|
||||||
|
monkeypatch.setattr(collector.sense, 'get_humidity', mock_humidity)
|
||||||
|
|
||||||
|
def mock_pressure():
|
||||||
|
return 1013.345
|
||||||
|
|
||||||
|
monkeypatch.setattr(collector.sense, 'get_pressure', mock_pressure)
|
||||||
|
collector.values_to_db()
|
||||||
|
temp = Temperature.objects.get(pk=1)
|
||||||
|
humidity = Humidity.objects.get(pk=1)
|
||||||
|
pressure = Pressure.objects.get(pk=1)
|
||||||
|
assert (temp.value == 25.3
|
||||||
|
and humidity.value == 45.2
|
||||||
|
and pressure.value == 1013.3)
|
||||||
|
|
Loading…
Reference in New Issue