diff --git a/mistral/db/sqlalchemy/model_base.py b/mistral/db/sqlalchemy/model_base.py index 94592cb05..060044dd8 100644 --- a/mistral/db/sqlalchemy/model_base.py +++ b/mistral/db/sqlalchemy/model_base.py @@ -66,6 +66,9 @@ class _MistralBase(oslo_models.ModelBase, oslo_models.TimestampMixin): return d + def __repr__(self): + return '%s %s' % (type(self).__name__, self.to_dict().__repr__()) + def datetime_to_str(dct, attr_name): if dct.get(attr_name) is not None: diff --git a/mistral/tests/unit/db/v2/test_sqlalchemy_db_api.py b/mistral/tests/unit/db/v2/test_sqlalchemy_db_api.py index 5f45613a8..d3ea07b68 100644 --- a/mistral/tests/unit/db/v2/test_sqlalchemy_db_api.py +++ b/mistral/tests/unit/db/v2/test_sqlalchemy_db_api.py @@ -155,6 +155,12 @@ class WorkbookTest(test_base.DbTestCase): self.assertEqual(created0, fetched[0]) self.assertEqual('public', created0['scope']) + def test_workbook_repr(self): + s = db_api.create_workbook(WORKBOOKS[0]).__repr__() + + self.assertIn('Workbook ', s) + self.assertIn("'name': 'my_workbook1'", s) + self.assertIn("'description': 'my description'", s) EXECUTIONS = [ { @@ -224,6 +230,13 @@ class ExecutionTest(test_base.DbTestCase): created['id'] ) + def test_execution_repr(self): + s = db_api.create_execution(EXECUTIONS[0]).__repr__() + + self.assertIn('Execution ', s) + self.assertIn("'id': '1'", s) + self.assertIn("'state': 'IDLE'", s) + TASKS = [ { @@ -334,6 +347,18 @@ class TaskTest(test_base.DbTestCase): created['id'] ) + def test_task_repr(self): + ex = db_api.create_execution(EXECUTIONS[0]) + + values = copy.copy(TASKS[0]) + values.update({'execution_id': ex.id}) + + s = db_api.create_task(values).__repr__() + + self.assertIn('Task ', s) + self.assertIn("'id': '1'", s) + self.assertIn("'name': 'my_task1'", s) + class TXTest(test_base.DbTestCase): def test_rollback(self):