Consistent created_at and updated_at timestamps when the test objects are created
Change-Id: I0cee8b09704acf69cd50ee108c91009fd33e6e74
This commit is contained in:
parent
68f4a57abd
commit
421e97213d
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue