def test_temperature(session):
    t = Temperature()
    t.humidity = 45.69
    t.temp = 19.94

    session.add(t)
    session.commit()

    b = session.query(Temperature).first()

    assert b is not None
    assert b == t
    assert b.humidity == t.humidity
    assert b.temp == t.temp
def test_monitor_temperatures(arduino, fake_temperatures):
    old_temp = fake_temperatures.timestamp
    monitor_temperatures()
    old_temp = Temperature.query.filter(Temperature.timestamp == old_temp).first()
    new_temp = Temperature.latest_temperature()

    assert naturally_equivalent(old_temp, new_temp) is False
    assert new_temp.temp == Decimal("33.4200")
    assert new_temp.humidity == Decimal("46.7400")
def fake_temperatures(session, request):
    test_temp, t2, t3 = Temperature(), Temperature(), Temperature()

    test_temp.temp = 25.52
    t2.temp = 26.63
    t3.temp = 27.74

    test_temp.humidity = 35.52
    t2.humidity = 36.63
    t3.humidity = 37.74

    test_temp.timestamp = arrow.utcnow().replace(minutes=-5)
    t2.timestamp = test_temp.timestamp.replace(minutes=-5)
    t3.timestamp = test_temp.timestamp.replace(minutes=-10)

    session.add_all([test_temp, t2, t3])

    session.commit()

    yield test_temp
def test_latest_temperature(fake_temperatures):
    fake_temp = fake_temperatures

    assert Temperature.latest_temperature() == fake_temp
    assert len(Temperature.query.all()) == 3