Skip to content

Commit 3ea5c5e

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add a test for the _joinedload_all helper"
2 parents 2074b54 + 4ff8ca8 commit 3ea5c5e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

nova/tests/unit/db/test_db_api.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,36 @@ def create_metadata_for_instance(self, instance_uuid):
191191
return meta, sys_meta
192192

193193

194+
class HelperTestCase(test.TestCase):
195+
@mock.patch.object(sqlalchemy_api, 'joinedload')
196+
def test_joinedload_helper(self, mock_jl):
197+
query = sqlalchemy_api._joinedload_all('foo.bar.baz')
198+
199+
# We call sqlalchemy.orm.joinedload() on the first element
200+
mock_jl.assert_called_once_with('foo')
201+
202+
# Then first.joinedload(second)
203+
column2 = mock_jl.return_value
204+
column2.joinedload.assert_called_once_with('bar')
205+
206+
# Then second.joinedload(third)
207+
column3 = column2.joinedload.return_value
208+
column3.joinedload.assert_called_once_with('baz')
209+
210+
self.assertEqual(column3.joinedload.return_value, query)
211+
212+
@mock.patch.object(sqlalchemy_api, 'joinedload')
213+
def test_joinedload_helper_single(self, mock_jl):
214+
query = sqlalchemy_api._joinedload_all('foo')
215+
216+
# We call sqlalchemy.orm.joinedload() on the first element
217+
mock_jl.assert_called_once_with('foo')
218+
219+
# We should have gotten back just the result of the joinedload()
220+
# call if there were no other elements
221+
self.assertEqual(mock_jl.return_value, query)
222+
223+
194224
class DecoratorTestCase(test.TestCase):
195225
def _test_decorator_wraps_helper(self, decorator):
196226
def test_func():

0 commit comments

Comments
 (0)