Beispiel #1
0
    def test_archive_long_enough_period_long(self, fakesensor,
                                             fake_data_resolution, settings):
        """Same as above but for a month. Need to freeze time for same reason as
        above test"""
        for k, v in settings.ZCONNECT_SETTINGS[
                "ARCHIVE_PRODUCT_AGGREGATIONS"].items():
            settings.ZCONNECT_SETTINGS["ARCHIVE_PRODUCT_AGGREGATIONS"][k][
                "period"] = "1month"

        with freeze_time("2018-06-03"):
            _generate_ts_data(fakesensor, fake_data_resolution)

            assert TimeSeriesDataArchive.objects.all().count() == 0

            archive_old_ts_data()

            assert TimeSeriesDataArchive.objects.all().count() == 3

            with patch(
                    "zconnect.zc_timeseries.tasks.DeviceSensor.archive_between"
            ) as pmock:
                archive_old_ts_data()

            # Will not happen again
            assert not pmock.called
            assert TimeSeriesDataArchive.objects.all().count() == 3
Beispiel #2
0
    def test_archive_no_data(self):
        """has settings, but no data to archive so should do nothing"""

        with patch("zconnect.zc_timeseries.tasks.DeviceSensor.archive_between"
                   ) as amock:
            archive_old_ts_data()

        assert not amock.called
Beispiel #3
0
def test_no_settings(fakesensor):
    """No settings - should do nothing"""

    with patch("zconnect.zc_timeseries.tasks.DeviceSensor.archive_between"
               ) as amock:
        archive_old_ts_data()

    assert not amock.called
Beispiel #4
0
    def test_archive_not_long_enough_period(self, fake_ts_data):
        """Tried to aggregate for a week but data didn't go back further than a
        week"""

        assert TimeSeriesDataArchive.objects.all().count() == 0

        with patch("zconnect.zc_timeseries.tasks.DeviceSensor.archive_between"
                   ) as amock:
            archive_old_ts_data()

        assert not amock.called

        assert TimeSeriesDataArchive.objects.all().count() == 0
Beispiel #5
0
    def test_archive_first(self, fake_ts_data_for_archiving,
                           fake_data_resolution):
        """Test that it can archive repeatedly"""

        assert TimeSeriesDataArchive.objects.all().count() == 0

        archive_old_ts_data()

        # one for each aggregation
        assert TimeSeriesDataArchive.objects.all().count() == 3

        # It should be able to run a few more times
        for i in range(0, fake_data_resolution, 60):
            archive_old_ts_data()

            j = i / 60
            assert TimeSeriesDataArchive.objects.all().count() == (j + 2) * 3
Beispiel #6
0
    def test_archive_long_enough_period(self, fake_ts_data_for_archiving):
        """the timeseries data straddles the week boundary so there will be
        'enough' in the PREVIOUS week to do an aggregation, but then when trying
        to do the next aggregation the period will straddle the current
        date/time so it will not do any archiving"""

        assert TimeSeriesDataArchive.objects.all().count() == 0

        archive_old_ts_data()

        # one for each aggregation
        assert TimeSeriesDataArchive.objects.all().count() == 3

        # It should run a second time without erroring and without archiving anything else
        with patch("zconnect.zc_timeseries.tasks.DeviceSensor.archive_between"
                   ) as pmock:
            archive_old_ts_data()

        # Will not happen again
        assert not pmock.called
        assert TimeSeriesDataArchive.objects.all().count() == 3
Beispiel #7
0
    def test_archive_not_long_enough_period_long(self, fakesensor,
                                                 fake_data_resolution,
                                                 settings):
        """Same, but with 'longer' period"""
        for k, v in settings.ZCONNECT_SETTINGS[
                "ARCHIVE_PRODUCT_AGGREGATIONS"].items():
            settings.ZCONNECT_SETTINGS["ARCHIVE_PRODUCT_AGGREGATIONS"][k][
                "period"] = "1month"

        # We generate ~a week of data, so need to freeze time to more than a
        # week after the start of the month so that snapping doesn't affect it
        with freeze_time("2018-06-26"):
            _generate_ts_data(fakesensor, fake_data_resolution)

            assert TimeSeriesDataArchive.objects.all().count() == 0

            with patch(
                    "zconnect.zc_timeseries.tasks.DeviceSensor.archive_between"
            ) as amock:
                archive_old_ts_data()

        assert not amock.called

        assert TimeSeriesDataArchive.objects.all().count() == 0