Fix broken unit test

This change mocks sqlalchemy.update during unit tests properly to avoid
the following error.

sqlalchemy.exc.ArgumentError: subject table for an INSERT, UPDATE or
DELETE expected, got <MagicMock name='models.Instance' id='...'>

Closes-Bug: #1938676
Change-Id: I5268132018e0a283bd35b5599cf8ca41968dde93
(cherry picked from commit 2800f0b62c)
This commit is contained in:
Takashi Kajinami 2021-08-02 17:20:27 +09:00 committed by zhurong
parent 2b3a4f3117
commit 623d6b49a0
1 changed files with 4 additions and 1 deletions

View File

@ -54,8 +54,10 @@ class TestInstances(test_base.MuranoTestCase):
mock_db_session.get_session().add.assert_called_once_with(
mock_models.Instance())
@mock.patch('murano.db.services.instances.sqlalchemy')
@mock.patch('murano.db.services.instances.models')
def test_track_instance_except_duplicate_entry(self, _, mock_db_session):
def test_track_instance_except_duplicate_entry(self, _, mock_sqlalchemy,
mock_db_session):
mock_db_session.get_session().add.side_effect =\
exception.DBDuplicateEntry
@ -64,6 +66,7 @@ class TestInstances(test_base.MuranoTestCase):
'test_type_name', 'test_type_title')
self.assertEqual(1, mock_db_session.get_session().execute.call_count)
self.assertEqual(1, mock_sqlalchemy.update().where.call_count)
@mock.patch('murano.db.services.instances.timeutils')
def test_destroy_instance(self, mock_timeutils, mock_db_session):