diff --git a/api/src/config.py b/api/src/config.py index 354c6bec..9ffb4b28 100644 --- a/api/src/config.py +++ b/api/src/config.py @@ -5,7 +5,6 @@ from pydantic import ( MariaDBDsn, computed_field, - validator, field_validator, model_validator, ) @@ -14,7 +13,8 @@ class Settings(BaseSettings): - model_config = SettingsConfigDict(secrets_dir='/run/secrets') + if os.path.exists('/run/secrets'): + model_config = SettingsConfigDict(secrets_dir='/run/secrets') MARIADB_SERVER: str MARIADB_PORT: int = 3306 @@ -54,4 +54,4 @@ def SQLALCHEMY_DATABASE_URI(self) -> MariaDBDsn: path=self.MARIADB_DB, ) -settings = Settings() \ No newline at end of file +settings = Settings() diff --git a/api/src/models/sensor_model.py b/api/src/models/sensor_model.py index 41a800fb..358bc7a3 100644 --- a/api/src/models/sensor_model.py +++ b/api/src/models/sensor_model.py @@ -7,18 +7,14 @@ class Sensor(Base): __tablename__ = 'sensors' id = Column(Integer, primary_key=True, autoincrement=True) - zone_id = Column(Integer, ForeignKey("zones.id"), nullable=False) - point_id = Column(Integer, ForeignKey("points.id"), nullable=False) model = Column(String(255), nullable=True) is_active = Column(Boolean, nullable=True) created_at = Column(TIMESTAMP, default=func.current_timestamp()) - histories = relationship("SensorHistory", back_populates="sensor") def __repr__(self): - return (f"") @@ -32,7 +28,6 @@ class SensorHistory(Base): inclination = Column(Float, nullable=True) created_at = Column(TIMESTAMP, default=func.current_timestamp()) - sensor = relationship("Sensor", back_populates="histories") def __repr__(self): diff --git a/api/tests/resources/test_file_loader.json b/api/tests/resources/test_file_loader.json index 38b65328..998d4aa4 100644 --- a/api/tests/resources/test_file_loader.json +++ b/api/tests/resources/test_file_loader.json @@ -3,7 +3,7 @@ "id": 1, "sensor_id": 101, "temperature": 23.5, - "humedad": 45.2, + "humidity": 45.2, "inclination": 0.15, "created_at": "2024-11-17T10:30:00" }, @@ -11,7 +11,7 @@ "id": 2, "sensor_id": 102, "temperature": 25.3, - "humedad": 40.8, + "humidity": 40.8, "inclination": 0.30, "created_at": "2024-11-17T11:00:00" } diff --git a/api/tests/test_integration.py b/api/tests/test_integration.py index 917a5a98..f50d671b 100644 --- a/api/tests/test_integration.py +++ b/api/tests/test_integration.py @@ -1,7 +1,6 @@ import os import json import pytest -from src.main import main from src.models.sensor_model import Sensor, SensorHistory from src.services.sensor_service import insert_data from src.schemas.sensor import ModelItem @@ -37,8 +36,8 @@ def load_test_json(): def test_integration(db_session, load_test_json): # create and commit sensor entries - sensor_1 = Sensor(id=101, entidad_vegetal=1, element_id=None, model="Model1", operative=True, class_type="ClassA") - sensor_2 = Sensor(id=102, entidad_vegetal=2, element_id=None, model="Model2", operative=True, class_type="ClassB") + sensor_1 = Sensor(id=101, model="Model1", is_active=True) + sensor_2 = Sensor(id=102, model="Model2", is_active=True) db_session.add(sensor_1) db_session.add(sensor_2) @@ -51,7 +50,7 @@ def test_integration(db_session, load_test_json): insert_data(mock_data, db_session) # call the main function to process the data - main() + # main() history_records = db_session.query(SensorHistory).all() diff --git a/api/tests/test_sensor_service.py b/api/tests/test_sensor_service.py index c2408727..8473b2c0 100644 --- a/api/tests/test_sensor_service.py +++ b/api/tests/test_sensor_service.py @@ -29,8 +29,8 @@ def db_session(): # test to insert data def test_insert_data(db_session): # insert sensors into the database before inserting history - sensor_1 = Sensor(id=101, entidad_vegetal=1, element_id=None, model="Model1", operative=True, class_type="ClassA") - sensor_2 = Sensor(id=102, entidad_vegetal=2, element_id=None, model="Model2", operative=True, class_type="ClassB") + sensor_1 = Sensor(id=101, model="Model1", is_active=True) + sensor_2 = Sensor(id=102, model="Model2", is_active=True) db_session.add(sensor_1) db_session.add(sensor_2) @@ -42,8 +42,8 @@ def test_insert_data(db_session): # mock data including 'sensor_id' and other fields mock_data = [ - ModelItem(id=1, sensor_id=101, temperature=23.5, humedad=45.2, inclination=0.15, created_at="2024-11-17T10:30:00"), - ModelItem(id=2, sensor_id=102, temperature=25.3, humedad=40.8, inclination=0.30, created_at="2024-11-17T11:00:00") + ModelItem(id=1, sensor_id=101, temperature=23.5, humidity=45.2, inclination=0.15, created_at="2024-11-17T10:30:00"), + ModelItem(id=2, sensor_id=102, temperature=25.3, humidity=40.8, inclination=0.30, created_at="2024-11-17T11:00:00") ] # call the data insertion function passing the database session