def test_sensor_values_returned_as_json(api_server): value = api_server.get("/sensors/").json python_version = PythonVersion().value() sensor_names = value.keys() assert "Python Version" in sensor_names assert value["Python Version"] == list(python_version)
def test_erroring_sensor_excluded_but_reported(self, api_server, api_key): from .test_utils import FailingSensor with mock.patch("apd.sensors.cli.get_sensors") as get_sensors: # Ensure failing sensor is first, to test that subsequent sensors # are still processed get_sensors.return_value = [FailingSensor(2), PythonVersion()] value = api_server.get("/sensors/", headers={"X-API-Key": api_key}).json second_attempt_value = api_server.get( "/sensors/", headers={"X-API-Key": api_key} ).json sensors = value["sensors"] failing = [sensor for sensor in sensors if sensor["id"] == "FailingSensor"] assert len(failing) == 0 errors = value["errors"] failing = [sensor for sensor in errors if sensor["id"] == "FailingSensor"] assert len(failing) == 1 python_version = [ sensor for sensor in sensors if sensor["id"] == "PythonVersion" ] assert len(python_version) == 1 sensors = second_attempt_value["sensors"] assert second_attempt_value["errors"] == [] failing = [sensor for sensor in sensors if sensor["id"] == "FailingSensor"] assert len(failing) == 1 python_version = [ sensor for sensor in sensors if sensor["id"] == "PythonVersion" ] assert len(python_version) == 1
def test_sensor_values_returned_as_json(self, api_server, api_key): value = api_server.get("/sensors/", headers={"X-API-Key": api_key}).json python_version = PythonVersion().value() sensor_names = value.keys() assert "Python Version" in sensor_names assert value["Python Version"] == list(python_version)
def test_sensor_values_returned_as_json(self, api_server, api_key): value = api_server.get("/sensors/", headers={"X-API-Key": api_key}).json sensors = value["sensors"] python_version = [ sensor for sensor in sensors if sensor["id"] == "PythonVersion" ][0] assert python_version["title"] == "Python Version" assert python_version["value"] == list(PythonVersion().value())
def test_erroring_sensor_shows_None(self, api_server, api_key): from .test_utils import FailingSensor with mock.patch("apd.sensors.cli.get_sensors") as get_sensors: # Ensure failing sensor is first, to test that subsequent sensors # are still processed get_sensors.return_value = [FailingSensor(10), PythonVersion()] value = api_server.get("/sensors/", headers={"X-API-Key": api_key}).json assert value["Sensor which fails"] is None assert "Python Version" in value.keys()
def test_erroring_sensor_shows_None(self, api_server, api_key): from .test_utils import FailingSensor with mock.patch("apd.sensors.cli.get_sensors") as get_sensors: # Ensure failing sensor is first, to test that subsequent sensors # are still processed get_sensors.return_value = [FailingSensor(10), PythonVersion()] value = api_server.get("/sensors/", headers={"X-API-Key": api_key}).json sensors = value["sensors"] failing = [sensor for sensor in sensors if sensor["id"] == "FailingSensor"][0] python_version = [ sensor for sensor in sensors if sensor["id"] == "PythonVersion" ][0] assert failing["title"] == "Sensor which fails" assert failing["value"] is None assert python_version["title"] == "Python Version"
def sensors() -> t.Iterator[t.List[Sensor[t.Any]]]: """Patch the get_sensors method to return a known pair of sensors only""" data: t.List[Sensor[t.Any]] = [PythonVersion(), ACStatus()] with patch("apd.sensors.cli.get_sensors") as get_sensors: get_sensors.return_value = data yield data
def sensor(): return PythonVersion()