Adding implementation of method __repr__ for DB models

Change-Id: I5ba1009a4ebf02b3da826c6dd5e78aa0ec9412f4
This commit is contained in:
Renat Akhmerov 2014-08-07 13:49:01 +07:00
parent 2e14bb0ea9
commit 2b243d79aa
2 changed files with 28 additions and 0 deletions

View File

@ -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:

View File

@ -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):