Skip to content
Snippets Groups Projects
Commit 56861662 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

SensorLineChartTile: Refactoring: group tests info class

parent 4f334b8d
No related branches found
No related tags found
No related merge requests found
import datetime
from unittest.mock import MagicMock
import pytest
from logic.tile.tiles.SensorLineChartTile import SensorLineChartTile, SensorType
@pytest.fixture()
def example_settings():
return {
"title": "My Room",
"url": "http://127.0.0.1:10003",
"sensorID": 1,
"sensorIDsForMinMax": [2, 3, 4],
"numberOfHoursToShow": 4,
"decimals": 1,
"lineColor": "rgba(254, 151, 0, 1)",
"fillColor": "rgba(254, 151, 0, 0.2)",
"showAxes": False,
"outdatedValueWarningLimitInSeconds": 300 # use -1 to disable warning
}
@pytest.fixture()
def example_settings_with_axes():
def example_settings(showAxes: bool):
return {
"title": "My Room",
"url": "http://127.0.0.1:10003",
......@@ -33,7 +14,7 @@ def example_settings_with_axes():
"decimals": 1,
"lineColor": "rgba(254, 151, 0, 1)",
"fillColor": "rgba(254, 151, 0, 0.2)",
"showAxes": True,
"showAxes": showAxes,
"outdatedValueWarningLimitInSeconds": 300 # use -1 to disable warning
}
......@@ -47,94 +28,87 @@ def storage_leaf_service_mock(minValue, maxValue):
return storageLeafServiceMock
class TestGetMinMax:
START_DATE = datetime.date(year=2021, month=2, day=8)
END_DATE = datetime.date(year=2021, month=2, day=9)
def test_humidity_returns_0_and_100(example_settings):
tile = SensorLineChartTile('mySensorTile', example_settings, 10)
def test_humidity_returns_0_and_100(self):
tile = SensorLineChartTile('mySensorTile', example_settings(False), 10)
yValues = ['12.5', '10.5']
result = tile._get_min_and_max('myPage',
SensorType.HUMIDITY,
START_DATE, END_DATE,
self.START_DATE, self.END_DATE,
storage_leaf_service_mock(15.0, 20.0),
yValues)
assert result == (0, 100)
def test_temperature_no_values_returns_min_and_max_of_api(example_settings):
tile = SensorLineChartTile('mySensorTile', example_settings, 10)
def test_temperature_no_values_returns_min_and_max_of_api(self):
tile = SensorLineChartTile('mySensorTile', example_settings(False), 10)
result = tile._get_min_and_max('myPage',
SensorType.TEMPERATURE,
START_DATE, END_DATE,
self.START_DATE, self.END_DATE,
storage_leaf_service_mock(15.0, 20.0),
[])
assert result == (-SensorLineChartTile.MAX_Y_AXIS_SPACING, 20 + SensorLineChartTile.MAX_Y_AXIS_SPACING)
def test_temperature_min_max_data_is_none_returns_zero(example_settings):
tile = SensorLineChartTile('mySensorTile', example_settings, 10)
def test_temperature_min_max_data_is_none_returns_zero(self):
tile = SensorLineChartTile('mySensorTile', example_settings(False), 10)
result = tile._get_min_and_max('myPage',
SensorType.TEMPERATURE,
START_DATE, END_DATE,
self.START_DATE, self.END_DATE,
storage_leaf_service_mock(None, None),
[])
assert result == (-SensorLineChartTile.MAX_Y_AXIS_SPACING, SensorLineChartTile.MAX_Y_AXIS_SPACING)
def test_temperature_min_is_above_zero_returns_zero_min(example_settings):
tile = SensorLineChartTile('mySensorTile', example_settings, 10)
def test_temperature_min_is_above_zero_returns_zero_min(self):
tile = SensorLineChartTile('mySensorTile', example_settings(False), 10)
result = tile._get_min_and_max('myPage',
SensorType.TEMPERATURE,
START_DATE, END_DATE,
self.START_DATE, self.END_DATE,
storage_leaf_service_mock(5, 6),
[])
assert result == (-SensorLineChartTile.MAX_Y_AXIS_SPACING, 6 + SensorLineChartTile.MAX_Y_AXIS_SPACING)
def test_temperature_min_is_below_zero_returns_min(example_settings):
tile = SensorLineChartTile('mySensorTile', example_settings, 10)
def test_temperature_min_is_below_zero_returns_min(self):
tile = SensorLineChartTile('mySensorTile', example_settings(False), 10)
result = tile._get_min_and_max('myPage',
SensorType.TEMPERATURE,
START_DATE, END_DATE,
self.START_DATE, self.END_DATE,
storage_leaf_service_mock(-3, 6),
[])
assert result == (-3 - SensorLineChartTile.MAX_Y_AXIS_SPACING, 6 + SensorLineChartTile.MAX_Y_AXIS_SPACING)
def test_temperature_show_axes_no_values(example_settings_with_axes):
tile = SensorLineChartTile('mySensorTile', example_settings_with_axes, 10)
def test_temperature_show_axes_no_values(self):
tile = SensorLineChartTile('mySensorTile', example_settings(True), 10)
result = tile._get_min_and_max('myPage',
SensorType.TEMPERATURE,
START_DATE, END_DATE,
self.START_DATE, self.END_DATE,
storage_leaf_service_mock(None, None),
[])
assert result == (-SensorLineChartTile.MAX_Y_AXIS_SPACING, SensorLineChartTile.MAX_Y_AXIS_SPACING)
def test_temperature_show_axes_values_above_zero_return_zero_min(example_settings_with_axes):
tile = SensorLineChartTile('mySensorTile', example_settings_with_axes, 10)
def test_temperature_show_axes_values_above_zero_return_zero_min(self):
tile = SensorLineChartTile('mySensorTile', example_settings(True), 10)
result = tile._get_min_and_max('myPage',
SensorType.TEMPERATURE,
START_DATE, END_DATE,
self.START_DATE, self.END_DATE,
storage_leaf_service_mock(None, None),
[6.0, 12])
assert result == (-SensorLineChartTile.MAX_Y_AXIS_SPACING, 12 + SensorLineChartTile.MAX_Y_AXIS_SPACING)
def test_temperature_show_axes_values_below_zero_return_min(example_settings_with_axes):
tile = SensorLineChartTile('mySensorTile', example_settings_with_axes, 10)
def test_temperature_show_axes_values_below_zero_return_min(self):
tile = SensorLineChartTile('mySensorTile', example_settings(True), 10)
result = tile._get_min_and_max('myPage',
SensorType.TEMPERATURE,
START_DATE, END_DATE,
self.START_DATE, self.END_DATE,
storage_leaf_service_mock(None, None),
[-6.0, 12])
assert result == (-6 - SensorLineChartTile.MAX_Y_AXIS_SPACING, 12 + SensorLineChartTile.MAX_Y_AXIS_SPACING)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment