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:
parent
b8f0708149
commit
8ec727dfc6
|
@ -2,7 +2,6 @@
|
|||
templates:
|
||||
- check-requirements
|
||||
- openstack-cover-jobs
|
||||
- openstack-lower-constraints-jobs
|
||||
- openstack-python3-victoria-jobs
|
||||
- periodic-stable-jobs
|
||||
- publish-openstack-docs-pti
|
||||
|
|
|
@ -113,18 +113,18 @@ class MuranoMigrationsCheckers(object):
|
|||
'enabled': True,
|
||||
'description': 'some text',
|
||||
'is_public': False,
|
||||
'tags': ['tag1', 'tag2'],
|
||||
'logo': b"logo blob here",
|
||||
'ui_definition': '{}',
|
||||
'owner_id': '123',
|
||||
'created': datetime.datetime.now(),
|
||||
'updated': datetime.datetime.now()
|
||||
}
|
||||
package_table.insert().execute(package)
|
||||
ins_stmt = package_table.insert(values=package)
|
||||
engine.execute(ins_stmt)
|
||||
|
||||
package['id'] = str(uuid.uuid4())
|
||||
self.assertRaises(db_exc.DBDuplicateEntry,
|
||||
package_table.insert().execute, package)
|
||||
engine.execute, ins_stmt)
|
||||
|
||||
def _check_002(self, engine, data):
|
||||
self.assertEqual('002', migration.version(engine))
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue