]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix mock return settings in test_full_uuids_skip_port_id_lookup
authorDane LeBlanc <leblancd@cisco.com>
Tue, 14 Apr 2015 15:05:40 +0000 (11:05 -0400)
committerDane LeBlanc <leblancd@cisco.com>
Tue, 14 Apr 2015 15:05:40 +0000 (11:05 -0400)
In the test_full_uuids_skip_port_id_lookup test in test_security_group.py,
there are a couple of problems with how a mock return value is being set
for a database query.

The first problem is that in this line:
    fmock = sess_mock.query.return_value.outerjoin.return_value.filter
there is a missing '.return_value' missing between 'sess_mock' and 'query'.

The second problem is that in this line:
    fmock.return_value.all.return_value = []
the 'all.return_value' should not be used.

For reference, the query for which this mock return value is being set
is in the get_sg_ids_grouped_by_port() method in ML2's db.py:
        query = session.query(models_v2.Port,
                              sg_db.SecurityGroupPortBinding.security_group_id)
        query = query.outerjoin(sg_db.SecurityGroupPortBinding,
                                models_v2.Port.id == sg_binding_port)
        query = query.filter(or_(*or_criteria))

This patch fixes the problems mentioned above so that the query above
returns an empty list for the test_full_uuids_skip_port_id_lookup test.

Change-Id: I2cec2c27fcdc82557c91205d202a6ac79987e92a
Closes-Bug: 1444009

neutron/tests/unit/plugins/ml2/test_security_group.py

index 6b1c3d016954c1006723b1096310501c9acfd9fb..d92ed87d62d448401ba31dae6699ca5c9dc2b15d 100644 (file)
@@ -146,10 +146,11 @@ class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase,
             mock.patch('neutron.plugins.ml2.db.or_'),
             mock.patch('neutron.plugins.ml2.db.db_api.get_session')
         ) as (or_mock, sess_mock):
-            fmock = sess_mock.query.return_value.outerjoin.return_value.filter
+            qmock = sess_mock.return_value.query
+            fmock = qmock.return_value.outerjoin.return_value.filter
             # return no ports to exit the method early since we are mocking
             # the query
-            fmock.return_value.all.return_value = []
+            fmock.return_value = []
             plugin.get_ports_from_devices([test_base._uuid(),
                                            test_base._uuid()])
             # the or_ function should only have one argument