From 7ddaea997810ad2f988a1842bfd8450fc7252b74 Mon Sep 17 00:00:00 2001 From: Tong Li Date: Mon, 23 Sep 2013 11:40:44 -0400 Subject: [PATCH] add more test cases to improve the test code coverage #2 In this patch, the following modules test coverage improved to 100% 1. ceilometer/storage/sqlalchemy/models Change-Id: Ie8a12ea07cb6c406f82cb29e8743fe67110c94c8 --- tests/storage/test_impl_sqlalchemy.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/storage/test_impl_sqlalchemy.py b/tests/storage/test_impl_sqlalchemy.py index 6b78d95e7..7a90100c4 100644 --- a/tests/storage/test_impl_sqlalchemy.py +++ b/tests/storage/test_impl_sqlalchemy.py @@ -24,10 +24,12 @@ """ import datetime +import repr from mock import patch from ceilometer.storage import models from ceilometer.storage.sqlalchemy.models import table_args +from ceilometer.storage.sqlalchemy import models as sql_models from ceilometer import utils from ceilometer.tests import db as tests_db @@ -38,6 +40,13 @@ class EventTestBase(tests_db.TestBase): database_connection = 'sqlite://' +class CeilometerBaseTest(EventTestBase): + def test_ceilometer_base(self): + base = sql_models.CeilometerBase() + base['key'] = 'value' + self.assertEqual(base['key'], 'value') + + class UniqueNameTest(EventTestBase): # UniqueName is a construct specific to sqlalchemy. # Not applicable to other drivers. @@ -55,6 +64,8 @@ class UniqueNameTest(EventTestBase): u2 = self.conn._get_or_create_unique_name("blah") self.assertNotEqual(u1.id, u2.id) self.assertNotEqual(u1.key, u2.key) + # Test the method __repr__ returns a string + self.assertTrue(repr.repr(u2)) class MyException(Exception): @@ -115,6 +126,16 @@ class EventTest(EventTestBase): for bad, event in problem_events: self.assertEquals(models.Event.UNKNOWN_PROBLEM, bad) + def test_get_none_value_traits(self): + model = sql_models.Trait(None, None, 5) + self.assertIsNone(model.get_value()) + self.assertTrue(repr.repr(model)) + + def test_event_repr(self): + ev = sql_models.Event('msg_id', None, False) + ev.id = 100 + self.assertTrue(repr.repr(ev)) + class ModelTest(tests_db.TestBase): database_connection = 'mysql://localhost'