Fix UTs to accommodate new_facade flag in OVO objects

In current UTs, in tests that do not actually touch databases,
we mock out refresh and expunge in current context. This will
not work under new engine facade, as new sessions are created
everytime.

We will need this fix when we set any object's new_facade flag
to True.

Closes-Bug: #1750735

Change-Id: I3a8bc06a671e37959e3014f8672b9a5e118c5c52
This commit is contained in:
Lujin 2018-03-09 16:05:05 +09:00
parent 25f4406c72
commit 3002df76d1
1 changed files with 16 additions and 0 deletions

View File

@ -695,6 +695,22 @@ class BaseObjectIfaceTestCase(_BaseObjectTestCase, test_base.BaseTestCase):
mock.patch.object(self.context.session, 'refresh').start()
mock.patch.object(self.context.session, 'expunge').start()
# don't validate expunge in tests that don't touch database and use
# new reader engine facade
self.reader_facade_mock = mock.patch.object(
self._test_class, 'db_context_reader').start()
mock.patch.object(self.reader_facade_mock.return_value.session,
'expunge').start()
# don't validate refresh and expunge in tests that don't touch database
# and use new writer engine facade
self.writer_facade_mock = mock.patch.object(
self._test_class, 'db_context_writer').start()
mock.patch.object(self.writer_facade_mock.return_value.session,
'expunge').start()
mock.patch.object(self.writer_facade_mock.return_value.session,
'refresh').start()
self.get_objects_mock = mock.patch.object(
obj_db_api, 'get_objects',
side_effect=self.fake_get_objects).start()