diff --git a/cloudpulse/objects/cpulse.py b/cloudpulse/objects/cpulse.py index a8cbf72..62862d0 100644 --- a/cloudpulse/objects/cpulse.py +++ b/cloudpulse/objects/cpulse.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import datetime from oslo_versionedobjects import fields from cloudpulse.common import exception @@ -148,6 +149,8 @@ class Cpulse(base.CloudpulsePersistentObject, base.CloudpulseObject, """ values = self.obj_get_changes() + values['created_at'] = datetime.datetime.utcnow() + values['updated_at'] = values['created_at'] LOG.info(_LI('Dumping CREATE test datastructure %s') % str(values)) db = self.dbapi.create_test(values) self._from_db_object(self, db) diff --git a/cloudpulse/tests/unit/objects/test_cpulse.py b/cloudpulse/tests/unit/objects/test_cpulse.py index 4e7646c..bacdc93 100644 --- a/cloudpulse/tests/unit/objects/test_cpulse.py +++ b/cloudpulse/tests/unit/objects/test_cpulse.py @@ -95,12 +95,36 @@ class TestCpulseObject(base.DbTestCase): self.assertEqual(self.context, cpulse[0]._context) def test_cpulse_create(self): + + def compare(self, other): + """Overload compare """ + + if type(self) != type(other): + return False + if self['name'] != other['name']: + return False + if self['uuid'] != other['uuid']: + return False + return True + + class Matcher(object): + """Matcher class """ + + def __init__(self, compare, exp): + self.compare = compare + self.exp = exp + + def __eq__(self, other): + return self.compare(self.exp, other) + with mock.patch.object(self.dbapi, 'create_test', autospec=True) as mock_create_test: mock_create_test.return_value = self.cpulsetest + cpulse = objects.Cpulse(self.context, **self.cpulsetest) cpulse.create() - mock_create_test.assert_called_once_with(self.cpulsetest) + mock_create_test.assert_called_once_with(Matcher(compare, + self.cpulsetest)) self.assertEqual(self.context, cpulse._context) def test_cpulse_destroy(self):