Beispiel #1
0
def test_save_device_desired_state_unkwon_device(rollback_registry, webserver,
                                                 some_desired_states, device,
                                                 data):
    registry = rollback_registry
    with pytest.raises(NoResultFound):
        webserver.post(f"/api/device/{device}/UNKNOWN/desired/state",
                       json=data)
Beispiel #2
0
def test_save_device_state_unkwon_device(rollback_registry, webserver):
    registry = rollback_registry
    State = registry.Iot.State
    count_before = State.query().count()
    with pytest.raises(NoResultFound):
        webserver.post(f"/api/device/relay/UNKNOWN/state",
                       data='{"is_open": true}')
Beispiel #3
0
def test_set_test_range(rollback_registry, webserver):
    registry = rollback_registry
    data = {"start": "08:11", "end": "3:22:30", "celsius": 15.5}
    expected_data = {"start": "08:11:00", "end": "03:22:30", "celsius": 15.5}
    r = webserver.post(f"/api/thermostat/range/22", json=data)
    assert r.status_code == 200, str(r)
    assert r.json() == expected_data

    data2 = {"start": "08:23", "end": "23:1", "celsius": 20.5}
    expected_data2 = {"start": "08:23:00", "end": "23:01:00", "celsius": 20.5}
    r = webserver.post(f"/api/thermostat/range/22", json=data2)
    assert r.status_code == 200, str(r)
    assert r.json() == expected_data2

    r = webserver.get(f"/api/thermostat/range/22", )
    assert r.status_code == 200, str(r)
    assert r.json() == expected_data2
Beispiel #4
0
def test_save_device_state(rollback_registry, webserver, engine):
    registry = rollback_registry
    State = registry.Iot.State
    count_before = State.query().count()
    response = webserver.post(f"/api/device/relay/{engine.code}/state",
                              json={"is_open": True})
    assert response.status_code == 200, str(response)
    assert count_before + 1 == State.query().count()
Beispiel #5
0
def test_save_device_desired_state_wrong_format(rollback_registry, webserver,
                                                engine, device, data):
    registry = rollback_registry
    State = registry.Iot.State
    count_before = State.query().count()
    response = webserver.post(
        f"/api/device/{device}/{engine.code}/desired/state", json=data)
    assert response.status_code == 422, str(response)
    assert count_before + 0 == State.query().count()
Beispiel #6
0
def test_save_device_state_wrong_format(rollback_registry, webserver, engine):
    registry = rollback_registry
    State = registry.Iot.State
    count_before = State.query().count()
    response = webserver.post(
        f"/api/device/relay/{engine.code}/state",
        data='{"is_open": "wrong type", "extra": true}',
    )
    assert response.status_code == 422, str(response)
    assert count_before + 0 == State.query().count()
Beispiel #7
0
def test_set_get_mode(
    rollback_registry,
    webserver,
):
    registry = rollback_registry
    mode = {"mode": "thermostat"}
    r = webserver.post(f"/api/mode", json=mode)
    assert r.status_code == 200, str(r)
    assert r.json() == mode
    r = webserver.get(f"/api/mode", )
    assert r.status_code == 200, str(r)
    assert r.json() == mode
Beispiel #8
0
def test_save_weather_station_packet(rollback_registry, webserver,
                                     weather_station):
    registry = rollback_registry
    State = registry.Iot.State
    count_before = State.query().count()
    response = webserver.post(
        f"/api/device/weather-station/aprs-packet",
        json={
            'raw':
            "FW5282>APRS,TCPXX*,qAX,CWOP-5:@192116z4759.58N/00227.12E_052/005g013t038r000p004P001h95b10271L000.DsVP",
        })
    assert response.status_code == 200, str(response)
    assert response.json()["station_code"] == weather_station.code
    assert count_before + 1 == State.query().count()
    with pytest.raises(IntegrityError):
        # same station_code/tiemstamp
        response = webserver.post(
            f"/api/device/weather-station/aprs-packet",
            json={
                'raw':
                "FW5282>APRS,TCPXX*,qAX,CWOP-5:@192116z4759.58N/00227.12E_052/005g013t038r000p004P001h95b10271L000.DsVP",
            },
        )
Beispiel #9
0
def test_save_weather_station_state(rollback_registry, webserver,
                                    weather_station):
    registry = rollback_registry
    State = registry.Iot.State
    count_before = State.query().count()
    response = webserver.post(
        f"/api/device/weather-station/{weather_station.code}/state",
        json={
            'station_code': weather_station.code,
            'sensor_date': "2020-06-15T11:42:00+00:00",
            'wind_direction': 52,
            'wind_speed': 2.2352,
            'wind_gust': 5.81152,
            'temperature': 3.333333333333333,
            'rain_1h': 0.0,
            'rain_24h': 1.016,
            'rain_since_midnight': 0.254,
            'humidity': 95,
            'pressure': 1027.1,
            'luminosity': 0
        })
    assert response.status_code == 200, str(response)
    assert count_before + 1 == State.query().count()
Beispiel #10
0
def test_save_thermostat_mode(rollback_registry, webserver, payload, response):
    r = webserver.post(f"/api/mode", json=payload)
    assert r.status_code == 200, str(r)
    assert r.json() == response