Ejemplo n.º 1
0
    def test_sensor_data_list_get_with_zone_filter(self, api_root):
        excluded_zone = Zone(
            name='Test Zone Excluded',
            notes='Zone notes.',
            key=uuid4()
        )
        excluded_zone.save()

        excluded_sensor = Sensor(
            guid=uuid4(),
            name='Test Sensor Excluded',
            notes='Sensor notes.',
            zone=excluded_zone,
            min_value=20,
            max_value=25,
            min_value_operator='>=',
            max_value_operator='<=',
            state=True,
            state_last_change_date=datetime.utcnow()
        )
        excluded_sensor.save()

        excluded_data = SensorData(
            sensor=excluded_sensor,
            datetime=datetime.utcnow(),
            value=22,
            state=True,
            state_changed=False
        )
        excluded_data.save()

        suffix = 'data/?zone_ids={}&format=json'.format(self.zone.id)
        response = requests.get(api_root + suffix)
        data = response.json()
        assert len(data) > 0

        excluded_data_json = [x for x in data if x['id'] == str(excluded_data.id)]
        assert len(excluded_data_json) == 0

        excluded_data.delete()
        excluded_sensor.delete()
        excluded_zone.delete()

        for i in range(3):
            data_json = [x for x in data if int(x['id']) == self.data[i].id][0]
            self._compare_sensor_data_json(self.data[i], data_json)
Ejemplo n.º 2
0
    def test_sensor_data_list_get_with_zone_filter(self, api_root):
        excluded_zone = Zone(name='Test Zone Excluded',
                             notes='Zone notes.',
                             key=uuid4())
        excluded_zone.save()

        excluded_sensor = Sensor(guid=uuid4(),
                                 name='Test Sensor Excluded',
                                 notes='Sensor notes.',
                                 zone=excluded_zone,
                                 min_value=20,
                                 max_value=25,
                                 min_value_operator='>=',
                                 max_value_operator='<=',
                                 state=True,
                                 state_last_change_date=datetime.utcnow())
        excluded_sensor.save()

        excluded_data = SensorData(sensor=excluded_sensor,
                                   datetime=datetime.utcnow(),
                                   value=22,
                                   state=True,
                                   state_changed=False)
        excluded_data.save()

        suffix = 'data/?zone_ids={}&format=json'.format(self.zone.id)
        response = requests.get(api_root + suffix)
        data = response.json()
        assert len(data) > 0

        excluded_data_json = [
            x for x in data if x['id'] == str(excluded_data.id)
        ]
        assert len(excluded_data_json) == 0

        excluded_data.delete()
        excluded_sensor.delete()
        excluded_zone.delete()

        for i in range(3):
            data_json = [x for x in data if int(x['id']) == self.data[i].id][0]
            self._compare_sensor_data_json(self.data[i], data_json)