From 35afdf17463eb970b04e8762988ef2274d622d96 Mon Sep 17 00:00:00 2001 From: Julia Varlamova Date: Tue, 20 May 2014 17:17:08 +0400 Subject: [PATCH] Enable skipped tests from test_models.py Enable test_modelbase_iteritems and test_modelbase_iter which were always skipped. These tests need a mapped object instead of ModelBase instance. Refactor ModelBaseTest a bit - move creation of ModelBase and ExtraKeysModel instances to setUp(). Refactor test_modelbase_iteritems and test_modelbase_iter to check if we can iterate over columns and extra_keys. Co-Authored-By: Oleksii Chuprykov Closes-Bug: #1312220 Change-Id: If19137cc81959031764c1b78f990b67a8912a304 --- tests/sqlalchemy/test_models.py | 55 +++++++++++++++++---------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/tests/sqlalchemy/test_models.py b/tests/sqlalchemy/test_models.py index fe5d2f0..257bf5c 100644 --- a/tests/sqlalchemy/test_models.py +++ b/tests/sqlalchemy/test_models.py @@ -26,6 +26,10 @@ BASE = declarative_base() class ModelBaseTest(test_base.DbTestCase): + def setUp(self): + super(ModelBaseTest, self).setUp() + self.mb = models.ModelBase() + self.ekm = ExtraKeysModel() def test_modelbase_has_dict_methods(self): dict_methods = ('__getitem__', @@ -41,16 +45,14 @@ class ModelBaseTest(test_base.DbTestCase): self.assertTrue(hasattr(models.ModelBase, method)) def test_modelbase_set(self): - mb = models.ModelBase() - mb['world'] = 'hello' - self.assertEqual(mb['world'], 'hello') + self.mb['world'] = 'hello' + self.assertEqual(self.mb['world'], 'hello') def test_modelbase_update(self): - mb = models.ModelBase() h = {'a': '1', 'b': '2'} - mb.update(h) + self.mb.update(h) for key in h.keys(): - self.assertEqual(mb[key], h[key]) + self.assertEqual(self.mb[key], h[key]) def test_modelbase_contains(self): mb = models.ModelBase() @@ -63,31 +65,33 @@ class ModelBaseTest(test_base.DbTestCase): self.assertFalse('non-existent-key' in mb) def test_modelbase_iteritems(self): - self.skipTest("Requires DB") - mb = models.ModelBase() h = {'a': '1', 'b': '2'} - mb.update(h) - for key, value in mb.iteritems(): - self.assertEqual(h[key], value) + expected = { + 'id': None, + 'smth': None, + 'name': 'NAME', + 'a': '1', + 'b': '2', + } + self.ekm.update(h) + self.assertEqual(dict(self.ekm.iteritems()), expected) def test_modelbase_iter(self): - self.skipTest("Requires DB") - mb = models.ModelBase() - h = {'a': '1', 'b': '2'} - mb.update(h) - i = iter(mb) - - min_items = len(h) + expected = { + 'id': None, + 'smth': None, + 'name': 'NAME', + } + i = iter(self.ekm) found_items = 0 while True: r = next(i, None) if r is None: break - - self.assertTrue(r in h) + self.assertEqual(expected[r[0]], r[1]) found_items += 1 - self.assertEqual(min_items, found_items) + self.assertEqual(len(expected), found_items) def test_modelbase_several_iters(self): mb = ExtraKeysModel() @@ -100,17 +104,14 @@ class ModelBaseTest(test_base.DbTestCase): def test_extra_keys_empty(self): """Test verifies that by default extra_keys return empty list.""" - mb = models.ModelBase() - self.assertEqual(mb._extra_keys, []) + self.assertEqual(self.mb._extra_keys, []) def test_extra_keys_defined(self): """Property _extra_keys will return list with attributes names.""" - ekm = ExtraKeysModel() - self.assertEqual(ekm._extra_keys, ['name']) + self.assertEqual(self.ekm._extra_keys, ['name']) def test_model_with_extra_keys(self): - item = ExtraKeysModel() - data = dict(item) + data = dict(self.ekm) self.assertEqual(data, {'smth': None, 'id': None, 'name': 'NAME'})