"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "cloudkitty/tests/storage/v1/test_storage.py" between
cloudkitty-8.0.0.tar.gz and cloudkitty-9.0.0.tar.gz

About: OpenStack CloudKitty provides Rating-as-a-Service for OpenStack.
The "Stein" series (latest release).

test_storage.py  (cloudkitty-8.0.0):test_storage.py  (cloudkitty-9.0.0)
skipping to change at line 19 skipping to change at line 19
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# @author: St├ęphane Albert # @author: St├ęphane Albert
# #
import copy import copy
import testtools
import mock import mock
import testscenarios import testscenarios
from cloudkitty import storage from cloudkitty import storage
from cloudkitty import tests from cloudkitty import tests
from cloudkitty.tests import samples from cloudkitty.tests import samples
from cloudkitty.tests import test_utils from cloudkitty.tests import utils as test_utils
from cloudkitty.tests.utils import is_functional_test
from cloudkitty import utils as ck_utils from cloudkitty import utils as ck_utils
class StorageTest(tests.TestCase): class StorageTest(tests.TestCase):
storage_scenarios = [ storage_scenarios = [
('sqlalchemy', dict(storage_backend='sqlalchemy')), ('sqlalchemy', dict(storage_backend='sqlalchemy')),
('hybrid', dict(storage_backend='hybrid'))] ('hybrid', dict(storage_backend='hybrid'))]
@classmethod @classmethod
def generate_scenarios(cls): def generate_scenarios(cls):
cls.scenarios = testscenarios.multiply_scenarios( cls.scenarios = testscenarios.multiply_scenarios(
skipping to change at line 67 skipping to change at line 65
self.storage.push(working_data, self._other_tenant_id) self.storage.push(working_data, self._other_tenant_id)
def insert_different_data_two_tenants(self): def insert_different_data_two_tenants(self):
working_data = copy.deepcopy(samples.RATED_DATA) working_data = copy.deepcopy(samples.RATED_DATA)
del working_data[1] del working_data[1]
self.storage.push(working_data, self._tenant_id) self.storage.push(working_data, self._tenant_id)
working_data = copy.deepcopy(samples.RATED_DATA) working_data = copy.deepcopy(samples.RATED_DATA)
del working_data[0] del working_data[0]
self.storage.push(working_data, self._other_tenant_id) self.storage.push(working_data, self._other_tenant_id)
@testtools.skipIf(is_functional_test(), 'Not a functional test')
class StorageDataframeTest(StorageTest): class StorageDataframeTest(StorageTest):
storage_scenarios = [ storage_scenarios = [
('sqlalchemy', dict(storage_backend='sqlalchemy'))] ('sqlalchemy', dict(storage_backend='sqlalchemy'))]
# Queries # Queries
# Data # Data
def test_get_no_frame_when_nothing_in_storage(self): def test_get_no_frame_when_nothing_in_storage(self):
self.assertRaises( self.assertRaises(
storage.NoTimeFrame, storage.NoTimeFrame,
skipping to change at line 130 skipping to change at line 127
end=samples.FIRST_PERIOD_END, end=samples.FIRST_PERIOD_END,
group_filters=group_filters) group_filters=group_filters)
def test_get_frame_on_two_periods(self): def test_get_frame_on_two_periods(self):
self.insert_different_data_two_tenants() self.insert_different_data_two_tenants()
data = self.storage.retrieve( data = self.storage.retrieve(
begin=samples.FIRST_PERIOD_BEGIN, begin=samples.FIRST_PERIOD_BEGIN,
end=samples.SECOND_PERIOD_END)['dataframes'] end=samples.SECOND_PERIOD_END)['dataframes']
self.assertEqual(3, len(data)) self.assertEqual(3, len(data))
@testtools.skipIf(is_functional_test(), 'Not a functional test')
class StorageTotalTest(StorageTest): class StorageTotalTest(StorageTest):
storage_scenarios = [ storage_scenarios = [
('sqlalchemy', dict(storage_backend='sqlalchemy'))] ('sqlalchemy', dict(storage_backend='sqlalchemy'))]
# Total # Total
def test_get_empty_total(self): def test_get_empty_total(self):
begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN - 3600) begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN - 3600)
end = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN) end = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN)
self.insert_data() self.insert_data()
total = self.storage.total( total = self.storage.total(
begin=begin, begin=begin,
end=end) end=end)['results']
self.assertEqual(1, len(total)) self.assertEqual(1, len(total))
self.assertEqual(total[0]["rate"], 0) self.assertEqual(total[0]["rate"], 0)
self.assertEqual(begin, total[0]["begin"]) self.assertEqual(begin, total[0]["begin"])
self.assertEqual(end, total[0]["end"]) self.assertEqual(end, total[0]["end"])
def test_get_total_without_filter_but_timestamp(self): def test_get_total_without_filter_but_timestamp(self):
begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN) begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN)
end = ck_utils.ts2dt(samples.SECOND_PERIOD_END) end = ck_utils.ts2dt(samples.SECOND_PERIOD_END)
self.insert_data() self.insert_data()
total = self.storage.total( total = self.storage.total(
begin=begin, begin=begin,
end=end) end=end)['results']
# FIXME(sheeprine): floating point error (transition to decimal) # FIXME(sheeprine): floating point error (transition to decimal)
self.assertEqual(1, len(total)) self.assertEqual(1, len(total))
self.assertEqual(1.9473999999999998, total[0]["rate"]) self.assertEqual(1.9473999999999998, total[0]["rate"])
self.assertEqual(begin, total[0]["begin"]) self.assertEqual(begin, total[0]["begin"])
self.assertEqual(end, total[0]["end"]) self.assertEqual(end, total[0]["end"])
def test_get_total_filtering_on_one_period(self): def test_get_total_filtering_on_one_period(self):
begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN) begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN)
end = ck_utils.ts2dt(samples.FIRST_PERIOD_END) end = ck_utils.ts2dt(samples.FIRST_PERIOD_END)
self.insert_data() self.insert_data()
total = self.storage.total( total = self.storage.total(
begin=begin, begin=begin,
end=end) end=end)['results']
self.assertEqual(1, len(total)) self.assertEqual(1, len(total))
self.assertEqual(1.1074, total[0]["rate"]) self.assertEqual(1.1074, total[0]["rate"])
self.assertEqual(begin, total[0]["begin"]) self.assertEqual(begin, total[0]["begin"])
self.assertEqual(end, total[0]["end"]) self.assertEqual(end, total[0]["end"])
def test_get_total_filtering_on_one_period_and_one_tenant(self): def test_get_total_filtering_on_one_period_and_one_tenant(self):
begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN) begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN)
end = ck_utils.ts2dt(samples.FIRST_PERIOD_END) end = ck_utils.ts2dt(samples.FIRST_PERIOD_END)
self.insert_data() self.insert_data()
group_filters = {'project_id': self._tenant_id} group_filters = {'project_id': self._tenant_id}
total = self.storage.total( total = self.storage.total(
begin=begin, begin=begin,
end=end, end=end,
group_filters=group_filters) group_filters=group_filters)['results']
self.assertEqual(1, len(total)) self.assertEqual(1, len(total))
self.assertEqual(0.5537, total[0]["rate"]) self.assertEqual(0.5537, total[0]["rate"])
self.assertEqual(self._tenant_id, total[0]["tenant_id"]) self.assertEqual(self._tenant_id, total[0]["tenant_id"])
self.assertEqual(begin, total[0]["begin"]) self.assertEqual(begin, total[0]["begin"])
self.assertEqual(end, total[0]["end"]) self.assertEqual(end, total[0]["end"])
def test_get_total_filtering_on_service(self): def test_get_total_filtering_on_service(self):
begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN) begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN)
end = ck_utils.ts2dt(samples.FIRST_PERIOD_END) end = ck_utils.ts2dt(samples.FIRST_PERIOD_END)
self.insert_data() self.insert_data()
total = self.storage.total( total = self.storage.total(
begin=begin, begin=begin,
end=end, end=end,
metric_types='instance') metric_types='instance')['results']
self.assertEqual(1, len(total)) self.assertEqual(1, len(total))
self.assertEqual(0.84, total[0]["rate"]) self.assertEqual(0.84, total[0]["rate"])
self.assertEqual('instance', total[0]["res_type"]) self.assertEqual('instance', total[0]["res_type"])
self.assertEqual(begin, total[0]["begin"]) self.assertEqual(begin, total[0]["begin"])
self.assertEqual(end, total[0]["end"]) self.assertEqual(end, total[0]["end"])
def test_get_total_groupby_tenant(self): def test_get_total_groupby_tenant(self):
begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN) begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN)
end = ck_utils.ts2dt(samples.SECOND_PERIOD_END) end = ck_utils.ts2dt(samples.SECOND_PERIOD_END)
self.insert_data() self.insert_data()
total = self.storage.total( total = self.storage.total(
begin=begin, begin=begin,
end=end, end=end,
groupby=['project_id']) groupby=['project_id'])['results']
self.assertEqual(2, len(total)) self.assertEqual(2, len(total))
self.assertEqual(0.9737, total[0]["rate"]) self.assertEqual(0.9737, total[0]["rate"])
self.assertEqual(self._other_tenant_id, total[0]["tenant_id"]) self.assertEqual(self._other_tenant_id, total[0]["tenant_id"])
self.assertEqual(begin, total[0]["begin"]) self.assertEqual(begin, total[0]["begin"])
self.assertEqual(end, total[0]["end"]) self.assertEqual(end, total[0]["end"])
self.assertEqual(0.9737, total[1]["rate"]) self.assertEqual(0.9737, total[1]["rate"])
self.assertEqual(self._tenant_id, total[1]["tenant_id"]) self.assertEqual(self._tenant_id, total[1]["tenant_id"])
self.assertEqual(begin, total[1]["begin"]) self.assertEqual(begin, total[1]["begin"])
self.assertEqual(end, total[1]["end"]) self.assertEqual(end, total[1]["end"])
def test_get_total_groupby_restype(self): def test_get_total_groupby_restype(self):
begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN) begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN)
end = ck_utils.ts2dt(samples.SECOND_PERIOD_END) end = ck_utils.ts2dt(samples.SECOND_PERIOD_END)
self.insert_data() self.insert_data()
total = self.storage.total( total = self.storage.total(
begin=begin, begin=begin,
end=end, end=end,
groupby=['type']) groupby=['type'])['results']
self.assertEqual(2, len(total)) self.assertEqual(2, len(total))
self.assertEqual(0.2674, total[0]["rate"]) self.assertEqual(0.2674, total[0]["rate"])
self.assertEqual('image.size', total[0]["res_type"]) self.assertEqual('image.size', total[0]["res_type"])
self.assertEqual(begin, total[0]["begin"]) self.assertEqual(begin, total[0]["begin"])
self.assertEqual(end, total[0]["end"]) self.assertEqual(end, total[0]["end"])
self.assertEqual(1.68, total[1]["rate"]) self.assertEqual(1.68, total[1]["rate"])
self.assertEqual('instance', total[1]["res_type"]) self.assertEqual('instance', total[1]["res_type"])
self.assertEqual(begin, total[1]["begin"]) self.assertEqual(begin, total[1]["begin"])
self.assertEqual(end, total[1]["end"]) self.assertEqual(end, total[1]["end"])
def test_get_total_groupby_tenant_and_restype(self): def test_get_total_groupby_tenant_and_restype(self):
begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN) begin = ck_utils.ts2dt(samples.FIRST_PERIOD_BEGIN)
end = ck_utils.ts2dt(samples.SECOND_PERIOD_END) end = ck_utils.ts2dt(samples.SECOND_PERIOD_END)
self.insert_data() self.insert_data()
total = self.storage.total( total = self.storage.total(
begin=begin, begin=begin,
end=end, end=end,
groupby=['project_id', 'type']) groupby=['project_id', 'type'])['results']
self.assertEqual(4, len(total)) self.assertEqual(4, len(total))
self.assertEqual(0.1337, total[0]["rate"]) self.assertEqual(0.1337, total[0]["rate"])
self.assertEqual(self._other_tenant_id, total[0]["tenant_id"]) self.assertEqual(self._other_tenant_id, total[0]["tenant_id"])
self.assertEqual('image.size', total[0]["res_type"]) self.assertEqual('image.size', total[0]["res_type"])
self.assertEqual(begin, total[0]["begin"]) self.assertEqual(begin, total[0]["begin"])
self.assertEqual(end, total[0]["end"]) self.assertEqual(end, total[0]["end"])
self.assertEqual(0.1337, total[1]["rate"]) self.assertEqual(0.1337, total[1]["rate"])
self.assertEqual(self._tenant_id, total[1]["tenant_id"]) self.assertEqual(self._tenant_id, total[1]["tenant_id"])
self.assertEqual('image.size', total[1]["res_type"]) self.assertEqual('image.size', total[1]["res_type"])
self.assertEqual(begin, total[1]["begin"]) self.assertEqual(begin, total[1]["begin"])
skipping to change at line 269 skipping to change at line 265
self.assertEqual(self._other_tenant_id, total[2]["tenant_id"]) self.assertEqual(self._other_tenant_id, total[2]["tenant_id"])
self.assertEqual('instance', total[2]["res_type"]) self.assertEqual('instance', total[2]["res_type"])
self.assertEqual(begin, total[2]["begin"]) self.assertEqual(begin, total[2]["begin"])
self.assertEqual(end, total[2]["end"]) self.assertEqual(end, total[2]["end"])
self.assertEqual(0.84, total[3]["rate"]) self.assertEqual(0.84, total[3]["rate"])
self.assertEqual(self._tenant_id, total[3]["tenant_id"]) self.assertEqual(self._tenant_id, total[3]["tenant_id"])
self.assertEqual('instance', total[3]["res_type"]) self.assertEqual('instance', total[3]["res_type"])
self.assertEqual(begin, total[3]["begin"]) self.assertEqual(begin, total[3]["begin"])
self.assertEqual(end, total[3]["end"]) self.assertEqual(end, total[3]["end"])
if not is_functional_test(): StorageTest.generate_scenarios()
StorageTest.generate_scenarios() StorageTotalTest.generate_scenarios()
StorageTotalTest.generate_scenarios() StorageDataframeTest.generate_scenarios()
StorageDataframeTest.generate_scenarios()
 End of changes. 13 change blocks. 
13 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)