Merge "api: enable v2 tests on SQLAlchemy & HBase"
This commit is contained in:
commit
df2f9d59c3
@ -20,7 +20,4 @@ from ceilometer.tests import api
|
||||
|
||||
|
||||
class FunctionalTest(api.FunctionalTest):
|
||||
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
PATH_PREFIX = '/v2'
|
||||
|
477
tests/api/v2/statistics.py
Normal file
477
tests/api/v2/statistics.py
Normal file
@ -0,0 +1,477 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 New Dream Network, LLC (DreamHost)
|
||||
#
|
||||
# Author: Doug Hellmann <doug.hellmann@dreamhost.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Test events statistics retrieval."""
|
||||
|
||||
import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from . import base
|
||||
from ceilometer import counter
|
||||
from ceilometer.storage.impl_mongodb import require_map_reduce
|
||||
from ceilometer.publisher import rpc
|
||||
|
||||
|
||||
class TestMaxProjectVolume(base.FunctionalTest):
|
||||
|
||||
PATH = '/meters/volume.size/statistics'
|
||||
|
||||
def setUp(self):
|
||||
super(TestMaxProjectVolume, self).setUp()
|
||||
require_map_reduce(self.conn)
|
||||
|
||||
self.counters = []
|
||||
for i in range(3):
|
||||
c = counter.Counter(
|
||||
'volume.size',
|
||||
'gauge',
|
||||
'GiB',
|
||||
5 + i,
|
||||
'user-id',
|
||||
'project1',
|
||||
'resource-id-%s' % i,
|
||||
timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i),
|
||||
resource_metadata={'display_name': 'test-volume',
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = rpc.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
}])
|
||||
self.assertEqual(data[0]['max'], 7)
|
||||
self.assertEqual(data[0]['count'], 3)
|
||||
|
||||
def test_start_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 7)
|
||||
self.assertEqual(data[0]['count'], 2)
|
||||
|
||||
def test_start_timestamp_after(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T12:34:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 5)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
def test_end_timestamp_before(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T09:54:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_start_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:32:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 6)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
|
||||
class TestMaxResourceVolume(base.FunctionalTest):
|
||||
|
||||
PATH = '/meters/volume.size/statistics'
|
||||
|
||||
def setUp(self):
|
||||
super(TestMaxResourceVolume, self).setUp()
|
||||
require_map_reduce(self.conn)
|
||||
|
||||
self.counters = []
|
||||
for i in range(3):
|
||||
c = counter.Counter(
|
||||
'volume.size',
|
||||
'gauge',
|
||||
'GiB',
|
||||
5 + i,
|
||||
'user-id',
|
||||
'project1',
|
||||
'resource-id',
|
||||
timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i),
|
||||
resource_metadata={'display_name': 'test-volume',
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = rpc.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
}])
|
||||
self.assertEqual(data[0]['max'], 7)
|
||||
self.assertEqual(data[0]['count'], 3)
|
||||
|
||||
def test_no_time_bounds_with_period(self):
|
||||
data = self.get_json(self.PATH,
|
||||
q=[{'field': 'resource_id',
|
||||
'value': 'resource-id'}],
|
||||
period=3600)
|
||||
self.assertEqual(len(data), 3)
|
||||
self.assertEqual(set(x['duration_start'] for x in data),
|
||||
set([u'2012-09-25T10:30:00',
|
||||
u'2012-09-25T12:32:00',
|
||||
u'2012-09-25T11:31:00']))
|
||||
self.assertEqual(data[0]['period'], 3600)
|
||||
self.assertEqual(set(x['period_start'] for x in data),
|
||||
set([u'2012-09-25T10:00:00',
|
||||
u'2012-09-25T11:00:00',
|
||||
u'2012-09-25T12:00:00']))
|
||||
|
||||
def test_start_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 7)
|
||||
self.assertEqual(data[0]['count'], 2)
|
||||
|
||||
def test_start_timestamp_after(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T12:34:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 5)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
def test_end_timestamp_before(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T09:54:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_start_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:32:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 6)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
|
||||
class TestSumProjectVolume(base.FunctionalTest):
|
||||
|
||||
PATH = '/meters/volume.size/statistics'
|
||||
|
||||
def setUp(self):
|
||||
super(TestSumProjectVolume, self).setUp()
|
||||
require_map_reduce(self.conn)
|
||||
|
||||
self.counters = []
|
||||
for i in range(3):
|
||||
c = counter.Counter(
|
||||
'volume.size',
|
||||
'gauge',
|
||||
'GiB',
|
||||
5 + i,
|
||||
'user-id',
|
||||
'project1',
|
||||
'resource-id-%s' % i,
|
||||
timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i),
|
||||
resource_metadata={'display_name': 'test-volume',
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = rpc.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
}])
|
||||
expected = 5 + 6 + 7
|
||||
self.assertEqual(data[0]['sum'], expected)
|
||||
self.assertEqual(data[0]['count'], 3)
|
||||
|
||||
def test_start_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
expected = 6 + 7
|
||||
self.assertEqual(data[0]['sum'], expected)
|
||||
self.assertEqual(data[0]['count'], 2)
|
||||
|
||||
def test_start_timestamp_after(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T12:34:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['sum'], 5)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
def test_end_timestamp_before(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T09:54:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_start_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:32:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['sum'], 6)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
|
||||
class TestSumResourceVolume(base.FunctionalTest):
|
||||
|
||||
PATH = '/meters/volume.size/statistics'
|
||||
|
||||
def setUp(self):
|
||||
super(TestSumResourceVolume, self).setUp()
|
||||
require_map_reduce(self.conn)
|
||||
|
||||
self.counters = []
|
||||
for i in range(3):
|
||||
c = counter.Counter(
|
||||
'volume.size',
|
||||
'gauge',
|
||||
'GiB',
|
||||
5 + i,
|
||||
'user-id',
|
||||
'project1',
|
||||
'resource-id',
|
||||
timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i),
|
||||
resource_metadata={'display_name': 'test-volume',
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = rpc.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
}])
|
||||
self.assertEqual(data[0]['sum'], 5 + 6 + 7)
|
||||
self.assertEqual(data[0]['count'], 3)
|
||||
|
||||
def test_no_time_bounds_with_period(self):
|
||||
data = self.get_json(self.PATH,
|
||||
q=[{'field': 'resource_id',
|
||||
'value': 'resource-id'}],
|
||||
period=1800)
|
||||
self.assertEqual(len(data), 3)
|
||||
self.assertEqual(set(x['duration_start'] for x in data),
|
||||
set([u'2012-09-25T10:30:00',
|
||||
u'2012-09-25T12:32:00',
|
||||
u'2012-09-25T11:31:00']))
|
||||
self.assertEqual(data[0]['period'], 1800)
|
||||
self.assertEqual(set(x['period_start'] for x in data),
|
||||
set([u'2012-09-25T10:30:00',
|
||||
u'2012-09-25T11:30:00',
|
||||
u'2012-09-25T12:30:00']))
|
||||
|
||||
def test_start_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
}])
|
||||
self.assertEqual(data[0]['sum'], 6 + 7)
|
||||
self.assertEqual(data[0]['count'], 2)
|
||||
|
||||
def test_start_timestamp_with_period(self):
|
||||
data = self.get_json(self.PATH,
|
||||
q=[{'field': 'resource_id',
|
||||
'value': 'resource-id'},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T10:15:00'}],
|
||||
period=7200)
|
||||
self.assertEqual(len(data), 2)
|
||||
self.assertEqual(set(x['duration_start'] for x in data),
|
||||
set([u'2012-09-25T10:30:00',
|
||||
u'2012-09-25T12:32:00']))
|
||||
self.assertEqual(data[0]['period'], 7200)
|
||||
self.assertEqual(set(x['period_start'] for x in data),
|
||||
set([u'2012-09-25T10:15:00',
|
||||
u'2012-09-25T12:15:00']))
|
||||
|
||||
def test_start_timestamp_after(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T12:34:00',
|
||||
}])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
}])
|
||||
self.assertEqual(data[0]['sum'], 5)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
def test_end_timestamp_before(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T09:54:00',
|
||||
}])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_start_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'lt',
|
||||
'value': '2012-09-25T11:32:00',
|
||||
}])
|
||||
self.assertEqual(data[0]['sum'], 6)
|
||||
self.assertEqual(data[0]['count'], 1)
|
@ -61,6 +61,9 @@ class TestApp(base.TestCase):
|
||||
|
||||
class TestApiMiddleware(FunctionalTest):
|
||||
|
||||
# This doesn't really matter
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
def test_json_parsable_error_middleware_404(self):
|
||||
response = self.get_json('/invalid_path',
|
||||
expect_errors=True,
|
||||
|
76
tests/api/v2/test_impl_hbase.py
Normal file
76
tests/api/v2/test_impl_hbase.py
Normal file
@ -0,0 +1,76 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
# from . import acl
|
||||
# from . import alarm
|
||||
# from . import compute_duration_by_resource
|
||||
# from . import list_events
|
||||
from . import list_meters
|
||||
# from . import list_resources
|
||||
from . import post_samples
|
||||
# from . import statistics
|
||||
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestAPIAcl(acl.TestAPIACL):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestListEvents(list_events.TestListEvents):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestListEmptyAlarms(alarm.TestListEmptyAlarms):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestAlarms(alarm.TestAlarms):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestComputeDurationByResource(
|
||||
# compute_duration_by_resource.TestComputeDurationByResource):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
|
||||
class TestListEmptyMeters(list_meters.TestListEmptyMeters):
|
||||
database_connection = 'hbase://__test__'
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestListMeters(list_meters.TestListMeters):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestListResources(list_resources.TestListResources):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestMaxProjectVolume(statistics.TestMaxProjectVolume):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestMaxResourceVolume(statistics.TestMaxResourceVolume):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestSumProjectVolume(statistics.TestSumProjectVolume):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
# TODO(jd) Fix the HBase driver to pass these tests!
|
||||
# class TestSumResourceVolume(statistics.TestSumProjectVolume):
|
||||
# database_connection = 'hbase://__test__'
|
||||
|
||||
|
||||
class TestPostSamples(post_samples.TestPostSamples):
|
||||
database_connection = 'hbase://__test__'
|
75
tests/api/v2/test_impl_mongodb.py
Normal file
75
tests/api/v2/test_impl_mongodb.py
Normal file
@ -0,0 +1,75 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from . import acl
|
||||
from . import alarm
|
||||
from . import compute_duration_by_resource
|
||||
from . import list_events
|
||||
from . import list_meters
|
||||
from . import list_resources
|
||||
from . import post_samples
|
||||
from . import statistics
|
||||
|
||||
|
||||
class TestAPIAcl(acl.TestAPIACL):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestListEvents(list_events.TestListEvents):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestListEmptyAlarms(alarm.TestListEmptyAlarms):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestAlarms(alarm.TestAlarms):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestComputeDurationByResource(
|
||||
compute_duration_by_resource.TestComputeDurationByResource):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestListEmptyMeters(list_meters.TestListEmptyMeters):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestListMeters(list_meters.TestListMeters):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestListResources(list_resources.TestListResources):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestMaxProjectVolume(statistics.TestMaxProjectVolume):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestMaxResourceVolume(statistics.TestMaxResourceVolume):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestSumProjectVolume(statistics.TestSumProjectVolume):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestSumResourceVolume(statistics.TestSumProjectVolume):
|
||||
database_connection = 'mongodb://__test__'
|
||||
|
||||
|
||||
class TestPostSamples(post_samples.TestPostSamples):
|
||||
database_connection = 'mongodb://__test__'
|
75
tests/api/v2/test_impl_sqlalchemy.py
Normal file
75
tests/api/v2/test_impl_sqlalchemy.py
Normal file
@ -0,0 +1,75 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from . import acl
|
||||
from . import alarm
|
||||
# from . import compute_duration_by_resource
|
||||
from . import list_events
|
||||
from . import list_meters
|
||||
from . import list_resources
|
||||
from . import post_samples
|
||||
# from . import statistics
|
||||
|
||||
|
||||
class TestAPIAcl(acl.TestAPIACL):
|
||||
database_connection = 'sqlite://'
|
||||
|
||||
|
||||
class TestListEvents(list_events.TestListEvents):
|
||||
database_connection = 'sqlite://'
|
||||
|
||||
|
||||
class TestListEmptyAlarms(alarm.TestListEmptyAlarms):
|
||||
database_connection = 'sqlite://'
|
||||
|
||||
|
||||
class TestAlarms(alarm.TestAlarms):
|
||||
database_connection = 'sqlite://'
|
||||
|
||||
# TODO(jd) fix SQL driver to pass this test!
|
||||
# class TestComputeDurationByResource(
|
||||
# compute_duration_by_resource.TestComputeDurationByResource):
|
||||
# database_connection = 'sqlite://'
|
||||
|
||||
|
||||
class TestListEmptyMeters(list_meters.TestListEmptyMeters):
|
||||
database_connection = 'sqlite://'
|
||||
|
||||
|
||||
class TestListMeters(list_meters.TestListMeters):
|
||||
database_connection = 'sqlite://'
|
||||
|
||||
|
||||
class TestListResources(list_resources.TestListResources):
|
||||
database_connection = 'sqlite://'
|
||||
|
||||
# TODO(jd) fix SQL driver to pass this test!
|
||||
# class TestMaxProjectVolume(statistics.TestMaxProjectVolume):
|
||||
# database_connection = 'sqlite://'
|
||||
|
||||
# TODO(jd) fix SQL driver to pass this test!
|
||||
# class TestMaxResourceVolume(statistics.TestMaxResourceVolume):
|
||||
# database_connection = 'sqlite://'
|
||||
|
||||
# TODO(jd) fix SQL driver to pass this test!
|
||||
# class TestSumProjectVolume(statistics.TestSumProjectVolume):
|
||||
# database_connection = 'sqlite:// '
|
||||
|
||||
# TODO(jd) fix SQL driver to pass this test!
|
||||
# class TestSumResourceVolume(statistics.TestSumProjectVolume):
|
||||
# database_connection = 'sqlite:// '
|
||||
|
||||
|
||||
class TestPostSamples(post_samples.TestPostSamples):
|
||||
database_connection = 'sqlite:// '
|
@ -1,131 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 New Dream Network, LLC (DreamHost)
|
||||
#
|
||||
# Author: Steven Berler <steven.berler@dreamhost.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Test getting the max resource volume.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.publisher import rpc
|
||||
from ceilometer import counter
|
||||
|
||||
from ceilometer.storage.impl_mongodb import require_map_reduce
|
||||
|
||||
from .base import FunctionalTest
|
||||
|
||||
|
||||
class TestMaxProjectVolume(FunctionalTest):
|
||||
|
||||
PATH = '/meters/volume.size/statistics'
|
||||
|
||||
def setUp(self):
|
||||
super(TestMaxProjectVolume, self).setUp()
|
||||
require_map_reduce(self.conn)
|
||||
|
||||
self.counters = []
|
||||
for i in range(3):
|
||||
c = counter.Counter(
|
||||
'volume.size',
|
||||
'gauge',
|
||||
'GiB',
|
||||
5 + i,
|
||||
'user-id',
|
||||
'project1',
|
||||
'resource-id-%s' % i,
|
||||
timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i),
|
||||
resource_metadata={'display_name': 'test-volume',
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = rpc.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
}])
|
||||
self.assertEqual(data[0]['max'], 7)
|
||||
self.assertEqual(data[0]['count'], 3)
|
||||
|
||||
def test_start_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 7)
|
||||
self.assertEqual(data[0]['count'], 2)
|
||||
|
||||
def test_start_timestamp_after(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T12:34:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 5)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
def test_end_timestamp_before(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T09:54:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_start_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:32:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 6)
|
||||
self.assertEqual(data[0]['count'], 1)
|
@ -1,146 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 New Dream Network, LLC (DreamHost)
|
||||
#
|
||||
# Author: Steven Berler <steven.berler@dreamhost.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Test getting the max resource volume.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.publisher import rpc
|
||||
from ceilometer import counter
|
||||
|
||||
from .base import FunctionalTest
|
||||
from ceilometer.storage.impl_mongodb import require_map_reduce
|
||||
|
||||
|
||||
class TestMaxResourceVolume(FunctionalTest):
|
||||
|
||||
PATH = '/meters/volume.size/statistics'
|
||||
|
||||
def setUp(self):
|
||||
super(TestMaxResourceVolume, self).setUp()
|
||||
require_map_reduce(self.conn)
|
||||
|
||||
self.counters = []
|
||||
for i in range(3):
|
||||
c = counter.Counter(
|
||||
'volume.size',
|
||||
'gauge',
|
||||
'GiB',
|
||||
5 + i,
|
||||
'user-id',
|
||||
'project1',
|
||||
'resource-id',
|
||||
timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i),
|
||||
resource_metadata={'display_name': 'test-volume',
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = rpc.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
}])
|
||||
self.assertEqual(data[0]['max'], 7)
|
||||
self.assertEqual(data[0]['count'], 3)
|
||||
|
||||
def test_no_time_bounds_with_period(self):
|
||||
data = self.get_json(self.PATH,
|
||||
q=[{'field': 'resource_id',
|
||||
'value': 'resource-id'}],
|
||||
period=3600)
|
||||
self.assertEqual(len(data), 3)
|
||||
self.assertEqual(set(x['duration_start'] for x in data),
|
||||
set([u'2012-09-25T10:30:00',
|
||||
u'2012-09-25T12:32:00',
|
||||
u'2012-09-25T11:31:00']))
|
||||
self.assertEqual(data[0]['period'], 3600)
|
||||
self.assertEqual(set(x['period_start'] for x in data),
|
||||
set([u'2012-09-25T10:00:00',
|
||||
u'2012-09-25T11:00:00',
|
||||
u'2012-09-25T12:00:00']))
|
||||
|
||||
def test_start_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 7)
|
||||
self.assertEqual(data[0]['count'], 2)
|
||||
|
||||
def test_start_timestamp_after(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T12:34:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 5)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
def test_end_timestamp_before(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T09:54:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_start_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:32:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['max'], 6)
|
||||
self.assertEqual(data[0]['count'], 1)
|
@ -15,19 +15,14 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Test listing raw events.
|
||||
"""
|
||||
"""Test statistics objects."""
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from ceilometer.api.controllers import v2
|
||||
from ceilometer.tests import base
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestStatisticsDuration(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -1,132 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 New Dream Network, LLC (DreamHost)
|
||||
#
|
||||
# Author: Steven Berler <steven.berler@dreamhost.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Test getting the sum project volume.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.publisher import rpc
|
||||
from ceilometer import counter
|
||||
|
||||
from .base import FunctionalTest
|
||||
from ceilometer.storage.impl_mongodb import require_map_reduce
|
||||
|
||||
|
||||
class TestSumProjectVolume(FunctionalTest):
|
||||
|
||||
PATH = '/meters/volume.size/statistics'
|
||||
|
||||
def setUp(self):
|
||||
super(TestSumProjectVolume, self).setUp()
|
||||
require_map_reduce(self.conn)
|
||||
|
||||
self.counters = []
|
||||
for i in range(3):
|
||||
c = counter.Counter(
|
||||
'volume.size',
|
||||
'gauge',
|
||||
'GiB',
|
||||
5 + i,
|
||||
'user-id',
|
||||
'project1',
|
||||
'resource-id-%s' % i,
|
||||
timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i),
|
||||
resource_metadata={'display_name': 'test-volume',
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = rpc.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
}])
|
||||
expected = 5 + 6 + 7
|
||||
self.assertEqual(data[0]['sum'], expected)
|
||||
self.assertEqual(data[0]['count'], 3)
|
||||
|
||||
def test_start_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
expected = 6 + 7
|
||||
self.assertEqual(data[0]['sum'], expected)
|
||||
self.assertEqual(data[0]['count'], 2)
|
||||
|
||||
def test_start_timestamp_after(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T12:34:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['sum'], 5)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
def test_end_timestamp_before(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T09:54:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_start_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'project_id',
|
||||
'value': 'project1',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:32:00',
|
||||
},
|
||||
])
|
||||
self.assertEqual(data[0]['sum'], 6)
|
||||
self.assertEqual(data[0]['count'], 1)
|
@ -1,158 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2012 New Dream Network, LLC (DreamHost)
|
||||
#
|
||||
# Author: Doug Hellmann <doug.hellmann@dreamhost.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Test getting the total resource volume.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from ceilometer.publisher import rpc
|
||||
from ceilometer import counter
|
||||
|
||||
from .base import FunctionalTest
|
||||
from ceilometer.storage.impl_mongodb import require_map_reduce
|
||||
|
||||
|
||||
class TestSumResourceVolume(FunctionalTest):
|
||||
|
||||
PATH = '/meters/volume.size/statistics'
|
||||
|
||||
def setUp(self):
|
||||
super(TestSumResourceVolume, self).setUp()
|
||||
require_map_reduce(self.conn)
|
||||
|
||||
self.counters = []
|
||||
for i in range(3):
|
||||
c = counter.Counter(
|
||||
'volume.size',
|
||||
'gauge',
|
||||
'GiB',
|
||||
5 + i,
|
||||
'user-id',
|
||||
'project1',
|
||||
'resource-id',
|
||||
timestamp=datetime.datetime(2012, 9, 25, 10 + i, 30 + i),
|
||||
resource_metadata={'display_name': 'test-volume',
|
||||
'tag': 'self.counter',
|
||||
}
|
||||
)
|
||||
self.counters.append(c)
|
||||
msg = rpc.meter_message_from_counter(
|
||||
c,
|
||||
cfg.CONF.publisher_rpc.metering_secret,
|
||||
'source1',
|
||||
)
|
||||
self.conn.record_metering_data(msg)
|
||||
|
||||
def test_no_time_bounds(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
}])
|
||||
self.assertEqual(data[0]['sum'], 5 + 6 + 7)
|
||||
self.assertEqual(data[0]['count'], 3)
|
||||
|
||||
def test_no_time_bounds_with_period(self):
|
||||
data = self.get_json(self.PATH,
|
||||
q=[{'field': 'resource_id',
|
||||
'value': 'resource-id'}],
|
||||
period=1800)
|
||||
self.assertEqual(len(data), 3)
|
||||
self.assertEqual(set(x['duration_start'] for x in data),
|
||||
set([u'2012-09-25T10:30:00',
|
||||
u'2012-09-25T12:32:00',
|
||||
u'2012-09-25T11:31:00']))
|
||||
self.assertEqual(data[0]['period'], 1800)
|
||||
self.assertEqual(set(x['period_start'] for x in data),
|
||||
set([u'2012-09-25T10:30:00',
|
||||
u'2012-09-25T11:30:00',
|
||||
u'2012-09-25T12:30:00']))
|
||||
|
||||
def test_start_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
}])
|
||||
self.assertEqual(data[0]['sum'], 6 + 7)
|
||||
self.assertEqual(data[0]['count'], 2)
|
||||
|
||||
def test_start_timestamp_with_period(self):
|
||||
data = self.get_json(self.PATH,
|
||||
q=[{'field': 'resource_id',
|
||||
'value': 'resource-id'},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T10:15:00'}],
|
||||
period=7200)
|
||||
self.assertEqual(len(data), 2)
|
||||
self.assertEqual(set(x['duration_start'] for x in data),
|
||||
set([u'2012-09-25T10:30:00',
|
||||
u'2012-09-25T12:32:00']))
|
||||
self.assertEqual(data[0]['period'], 7200)
|
||||
self.assertEqual(set(x['period_start'] for x in data),
|
||||
set([u'2012-09-25T10:15:00',
|
||||
u'2012-09-25T12:15:00']))
|
||||
|
||||
def test_start_timestamp_after(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T12:34:00',
|
||||
}])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
}])
|
||||
self.assertEqual(data[0]['sum'], 5)
|
||||
self.assertEqual(data[0]['count'], 1)
|
||||
|
||||
def test_end_timestamp_before(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'le',
|
||||
'value': '2012-09-25T09:54:00',
|
||||
}])
|
||||
self.assertEqual(data, [])
|
||||
|
||||
def test_start_end_timestamp(self):
|
||||
data = self.get_json(self.PATH, q=[{'field': 'resource_id',
|
||||
'value': 'resource-id',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'ge',
|
||||
'value': '2012-09-25T11:30:00',
|
||||
},
|
||||
{'field': 'timestamp',
|
||||
'op': 'lt',
|
||||
'value': '2012-09-25T11:32:00',
|
||||
}])
|
||||
self.assertEqual(data[0]['sum'], 6)
|
||||
self.assertEqual(data[0]['count'], 1)
|
Loading…
x
Reference in New Issue
Block a user