Example #1
0
    def test_get_newest_notification_returns_newest_record(self, sqlalchemy):
        sensor_service = SensorReadingPersistenceService()

        reading = AnalogSensorReading()
        reading.name = 'Test Sensor'
        sensor_service.create(reading)

        old_notification = NotificationEvent()
        old_notification.sensor_id = reading.id
        old_notification.timestamp = datetime(2015, 1, 1)

        new_notification = NotificationEvent()
        new_notification.sensor_id = reading.id
        new_notification.timestamp = datetime(2016, 1, 1)

        service = NotificationPersistenceService()

        # Insert in reverse order to confirm order by
        service.create(new_notification)
        service.create(old_notification)

        newest_timestamp = new_notification.timestamp
        db_timestamp = service.get_newest_notification(reading.name).timestamp

        assert db_timestamp == newest_timestamp
Example #2
0
    def test_get_newest_notification_returns_newest_record(self, sqlalchemy):
        sensor_service = SensorReadingPersistenceService()

        reading = AnalogSensorReading()
        reading.name = 'Test Sensor'
        sensor_service.create(reading)

        old_notification = NotificationEvent()
        old_notification.sensor_id = reading.id
        old_notification.timestamp = datetime(2015, 1, 1)

        new_notification = NotificationEvent()
        new_notification.sensor_id = reading.id
        new_notification.timestamp = datetime(2016, 1, 1)

        service = NotificationPersistenceService()

        # Insert in reverse order to confirm order by
        service.create(new_notification)
        service.create(old_notification)

        newest_timestamp = new_notification.timestamp
        db_timestamp = service.get_newest_notification(reading.name).timestamp

        assert db_timestamp == newest_timestamp
Example #3
0
    def test_sensor_reading_job_no_notifications_within_four_hours(
            self, sensormodule, sqlalchemy):
        tests.fixtures.mock_sensors = [mocks.MockDigitalAbnormalSensor]

        sensormodule.sensor_reading_job()
        sensormodule.sensor_reading_job()

        sensor_persistence = NotificationPersistenceService()

        assert len(sensor_persistence.all()) == 1
Example #4
0
    def test_sensor_reading_job_no_notifications_within_four_hours(
            self, sensormodule, sqlalchemy):
        tests.fixtures.mock_sensors = [mocks.MockDigitalAbnormalSensor]

        sensormodule.sensor_reading_job()
        sensormodule.sensor_reading_job()

        sensor_persistence = NotificationPersistenceService()

        assert len(sensor_persistence.all()) == 1
Example #5
0
    def test_sensor_reading_job_notifications_after_four_hours(
            self, sensormodule, sqlalchemy):
        tests.fixtures.mock_sensors = [mocks.MockDigitalAbnormalSensor]

        sensor_persistence = NotificationPersistenceService()

        sensormodule.sensor_reading_job()

        notification = sensor_persistence.get_newest_notification(
            'digital abnormal')
        notification.timestamp = datetime(1970, 1, 1)
        sensor_persistence.update(notification)

        sensormodule.sensor_reading_job()

        assert len(sensor_persistence.all()) == 2
Example #6
0
    def test_sensor_reading_job_notifications_after_four_hours(
            self, sensormodule, sqlalchemy):
        tests.fixtures.mock_sensors = [mocks.MockDigitalAbnormalSensor]

        sensor_persistence = NotificationPersistenceService()

        sensormodule.sensor_reading_job()

        notification = sensor_persistence.get_newest_notification(
            'digital abnormal')
        notification.timestamp = datetime(1970, 1, 1)
        sensor_persistence.update(notification)

        sensormodule.sensor_reading_job()

        assert len(sensor_persistence.all()) == 2
Example #7
0
    def test_get_newest_notification_excludes_other_sensors(self, sqlalchemy):
        reading_service = SensorReadingPersistenceService()
        notification_service = NotificationPersistenceService()

        included_sensor = DigitalSensorReading()
        included_sensor.name = 'included'
        reading_service.create(included_sensor)

        excluded_sensor = DigitalSensorReading()
        excluded_sensor.name = 'excluded'
        reading_service.create(excluded_sensor)

        excluded_notification = NotificationEvent()
        excluded_notification.sensor_id = excluded_sensor.id
        excluded_notification.timestamp = datetime(2016, 1, 1)
        notification_service.create(excluded_notification)

        included_notification = NotificationEvent()
        included_notification.sensor_id = included_sensor.id
        included_notification.timestamp = datetime(2015, 1, 1)
        notification_service.create(included_notification)

        assert notification_service.get_newest_notification('included') \
            .timestamp == included_notification.timestamp
Example #8
0
    def test_get_newest_notification_excludes_other_sensors(self, sqlalchemy):
        reading_service = SensorReadingPersistenceService()
        notification_service = NotificationPersistenceService()

        included_sensor = DigitalSensorReading()
        included_sensor.name = 'included'
        reading_service.create(included_sensor)

        excluded_sensor = DigitalSensorReading()
        excluded_sensor.name = 'excluded'
        reading_service.create(excluded_sensor)

        excluded_notification = NotificationEvent()
        excluded_notification.sensor_id = excluded_sensor.id
        excluded_notification.timestamp = datetime(2016, 1, 1)
        notification_service.create(excluded_notification)

        included_notification = NotificationEvent()
        included_notification.sensor_id = included_sensor.id
        included_notification.timestamp = datetime(2015, 1, 1)
        notification_service.create(included_notification)

        assert notification_service.get_newest_notification('included') \
            .timestamp == included_notification.timestamp