コード例 #1
0
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)
コード例 #2
0
    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
コード例 #3
0
    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)
コード例 #4
0
    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())
コード例 #5
0
    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()
コード例 #6
0
    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"
コード例 #7
0
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
コード例 #8
0
def sensor():
    return PythonVersion()