diff --git a/quantum/db/model_base.py b/quantum/db/model_base.py index e3ffa682c..db3b36a39 100644 --- a/quantum/db/model_base.py +++ b/quantum/db/model_base.py @@ -51,6 +51,14 @@ class QuantumBase(object): local.update(joined) return local.iteritems() + def __repr__(self): + """sqlalchemy based automatic __repr__ method""" + items = ['%s=%r' % (col.name, getattr(self, col.name)) + for col in self.__table__.columns] + return "<%s.%s[object at %x] {%s}>" % (self.__class__.__module__, + self.__class__.__name__, + id(self), ', '.join(items)) + class QuantumBaseV2(QuantumBase): diff --git a/quantum/tests/unit/test_db_plugin.py b/quantum/tests/unit/test_db_plugin.py index 65e0823c6..266cb4120 100644 --- a/quantum/tests/unit/test_db_plugin.py +++ b/quantum/tests/unit/test_db_plugin.py @@ -2782,3 +2782,19 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase): req = self.new_delete_request('subnets', subnet['subnet']['id']) res = req.get_response(self.api) self.assertEqual(res.status_int, 204) + + +class DbModelTestCase(unittest2.TestCase): + """ DB model tests """ + def test_repr(self): + """ testing the string representation of 'model' classes """ + network = models_v2.Network(name="net_net", status="OK", + admin_state_up=True) + actual_repr_output = repr(network) + exp_start_with = "") + final_exp = exp_start_with + exp_middle + exp_end_with + self.assertEqual(actual_repr_output, final_exp)