Пример #1
0
class TestTimeSeries(object):
    def setup_method(self):
        self.client = MockRedisClient()
        self.timeseries = TimeSeries(self.client, 'test')
        timestamps = [0, 0, 1, 1, 1, 60]

        for timestamp in timestamps:
            self.timeseries.insert(timestamp)

    def teardown_method(self):
        pass

    def test_insert(self):
        assert int(float(self.client._data['test:1sec:0'])) == 2
        assert int(float(self.client._data['test:1sec:1'])) == 3
        assert int(float(self.client._data['test:1sec:60'])) == 1
        assert int(float(self.client._data['test:1min:0'])) == 5
        assert int(float(self.client._data['test:1min:60'])) == 1
        assert int(float(self.client._data['test:1hour:0'])) == 6
        assert int(float(self.client._data['test:1day:0'])) == 6

    def test_fetch(self):
        begin_timestamp = 0
        end_timestamp = 60

        results = self.timeseries.fetch('1min', begin_timestamp, end_timestamp)
        assert results[0]['timestamp'] == 0
        assert int(float(results[0]['value'])) == 5
        assert int(float(results[1]['timestamp'])) == 60
        assert int(float(results[1]['value'])) == 1