repository to manage all files related to the makeathon farm bot project (Software + Documentation).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_plantdatabase.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #
  2. # created by caliskan
  3. # use this file to test your plantdatabase changes
  4. from software.backend.plantdatabase import PlantDataBase
  5. import pytest
  6. def test_create_table():
  7. testdatabase = PlantDataBase(database_name='test_database.db')
  8. assert testdatabase.create_tables() is True
  9. def test_insert_and_delete_plant():
  10. testdatabase = PlantDataBase(database_name='test_database.db')
  11. assert testdatabase.create_tables() is True
  12. assert testdatabase.delete_data("plants") is True
  13. assert testdatabase.insert_plant(plantname="Bertha", plant_id=1) is True
  14. assert testdatabase.plant_count() == 1
  15. assert testdatabase.delete_plant(plant_id=1) is True
  16. assert testdatabase.plant_count() == 0
  17. def test_insert_and_get_measurement_values():
  18. test_plant_id = 2
  19. test_temp = 22.4
  20. test_humidity = 93.4
  21. test_soil_moisture = 12.5
  22. test_brightness = 66
  23. test_plant_name = "Bertha"
  24. testdatabase = PlantDataBase(database_name='test_database.db')
  25. assert testdatabase.create_tables() is True
  26. assert testdatabase.delete_data("plants") is True
  27. assert testdatabase.insert_plant(plantname=test_plant_name, plant_id=test_plant_id) is True
  28. assert testdatabase.insert_measurement_data(plant_id=test_plant_id,
  29. sensordata_temp=test_temp,
  30. sensordata_humidity=test_humidity,
  31. sensordata_soil_moisture=test_soil_moisture,
  32. sensordata_brightness=test_brightness) is True
  33. test_plant_data = testdatabase.get_latest_data(plant_name=test_plant_name)
  34. print(test_plant_data)
  35. assert test_plant_data["PlantID"] == test_plant_id
  36. assert test_plant_data["AirTemperature"] == test_temp
  37. assert test_plant_data["AirHumidity"] == test_humidity
  38. assert test_plant_data["SoilMoisture"] == test_soil_moisture
  39. assert test_plant_data["Brightness"] == test_brightness
  40. assert test_plant_data["PlantName"] == test_plant_name