summaryrefslogtreecommitdiff
path: root/neutron/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-06-01 11:36:15 +0000
committerGerrit Code Review <review@openstack.org>2016-06-01 11:36:16 +0000
commite9b83fd4ce2e39018044f529170e817ba3d833d0 (patch)
tree12068e9dd6487f1f5d44e68da0f5d0df2c2981e9 /neutron/tests
parent10a713824517d6e637f041a95a165ce6b40deea6 (diff)
parent5decc850f126d74b89ec79593afcc68b9e8988e6 (diff)
downloadneutron-e9b83fd4ce2e39018044f529170e817ba3d833d0.tar.gz
Merge "objects: support advanced criteria for get_objects"
Diffstat (limited to 'neutron/tests')
-rw-r--r--neutron/tests/unit/objects/db/__init__.py0
-rw-r--r--neutron/tests/unit/objects/db/test_api.py49
-rw-r--r--neutron/tests/unit/objects/qos/test_policy.py4
-rw-r--r--neutron/tests/unit/objects/test_base.py27
-rw-r--r--neutron/tests/unit/plugins/ml2/test_plugin.py4
5 files changed, 78 insertions, 6 deletions
diff --git a/neutron/tests/unit/objects/db/__init__.py b/neutron/tests/unit/objects/db/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/neutron/tests/unit/objects/db/__init__.py
diff --git a/neutron/tests/unit/objects/db/test_api.py b/neutron/tests/unit/objects/db/test_api.py
new file mode 100644
index 0000000000..2f967d62b5
--- /dev/null
+++ b/neutron/tests/unit/objects/db/test_api.py
@@ -0,0 +1,49 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import mock
+
+from neutron import context
+from neutron import manager
+from neutron.objects import base
+from neutron.objects.db import api
+from neutron.tests import base as test_base
+
+
+PLUGIN_NAME = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2'
+
+
+class GetObjectsTestCase(test_base.BaseTestCase):
+
+ def setUp(self):
+ super(GetObjectsTestCase, self).setUp()
+ # TODO(ihrachys): revisit plugin setup once we decouple
+ # objects.db.objects.api from core plugin instance
+ self.setup_coreplugin(PLUGIN_NAME)
+
+ def test_get_objects_pass_marker_obj_when_limit_and_marker_passed(self):
+ ctxt = context.get_admin_context()
+ model = mock.sentinel.model
+ marker = mock.sentinel.marker
+ limit = mock.sentinel.limit
+ pager = base.Pager(marker=marker, limit=limit)
+
+ plugin = manager.NeutronManager.get_plugin()
+ with mock.patch.object(plugin, '_get_collection') as get_collection:
+ with mock.patch.object(api, 'get_object') as get_object:
+ api.get_objects(ctxt, model, _pager=pager)
+ get_object.assert_called_with(ctxt, model, id=marker)
+ get_collection.assert_called_with(
+ ctxt, model, mock.ANY,
+ filters={},
+ limit=limit,
+ marker_obj=get_object.return_value)
diff --git a/neutron/tests/unit/objects/qos/test_policy.py b/neutron/tests/unit/objects/qos/test_policy.py
index cb60901b8c..290e9c9e0c 100644
--- a/neutron/tests/unit/objects/qos/test_policy.py
+++ b/neutron/tests/unit/objects/qos/test_policy.py
@@ -65,7 +65,7 @@ class QosPolicyObjectTestCase(test_base.BaseObjectIfaceTestCase):
objs = self._test_class.get_objects(self.context)
context_mock.assert_called_once_with()
self.get_objects.assert_any_call(
- admin_context, self._test_class.db_model)
+ admin_context, self._test_class.db_model, _pager=None)
self._validate_objects(self.db_objs, objs)
def test_get_objects_valid_fields(self):
@@ -85,7 +85,7 @@ class QosPolicyObjectTestCase(test_base.BaseObjectIfaceTestCase):
**self.valid_field_filter)
context_mock.assert_called_once_with()
get_objects_mock.assert_any_call(
- admin_context, self._test_class.db_model,
+ admin_context, self._test_class.db_model, _pager=None,
**self.valid_field_filter)
self._validate_objects([self.db_obj], objs)
diff --git a/neutron/tests/unit/objects/test_base.py b/neutron/tests/unit/objects/test_base.py
index 55d2b429ec..02804ebf4a 100644
--- a/neutron/tests/unit/objects/test_base.py
+++ b/neutron/tests/unit/objects/test_base.py
@@ -370,7 +370,7 @@ class BaseObjectIfaceTestCase(_BaseObjectTestCase, test_base.BaseTestCase):
field].objname)[0]
mock_calls.append(
mock.call(
- self.context, obj_class.db_model,
+ self.context, obj_class.db_model, _pager=None,
**{k: db_obj[v]
for k, v in obj_class.foreign_keys.items()}))
return mock_calls
@@ -381,7 +381,9 @@ class BaseObjectIfaceTestCase(_BaseObjectTestCase, test_base.BaseTestCase):
side_effect=self.fake_get_objects) as get_objects_mock:
objs = self._test_class.get_objects(self.context)
self._validate_objects(self.db_objs, objs)
- mock_calls = [mock.call(self.context, self._test_class.db_model)]
+ mock_calls = [
+ mock.call(self.context, self._test_class.db_model, _pager=None)
+ ]
mock_calls.extend(self._get_synthetic_fields_get_objects_calls(
self.db_objs))
get_objects_mock.assert_has_calls(mock_calls)
@@ -395,8 +397,10 @@ class BaseObjectIfaceTestCase(_BaseObjectTestCase, test_base.BaseTestCase):
**self.valid_field_filter)
self._validate_objects(self.db_objs, objs)
- mock_calls = [mock.call(self.context, self._test_class.db_model,
- **self.valid_field_filter)]
+ mock_calls = [
+ mock.call(self.context, self._test_class.db_model, _pager=None,
+ **self.valid_field_filter)
+ ]
mock_calls.extend(self._get_synthetic_fields_get_objects_calls(
[self.db_obj]))
get_objects_mock.assert_has_calls(mock_calls)
@@ -628,6 +632,13 @@ class BaseObjectIfaceTestCase(_BaseObjectTestCase, test_base.BaseTestCase):
dict_ = obj.to_dict()
self.assertEqual(child_dict, dict_[field])
+ def test_get_objects_pager_is_passed_through(self):
+ with mock.patch.object(obj_db_api, 'get_objects') as get_objects:
+ pager = base.Pager()
+ self._test_class.get_objects(self.context, _pager=pager)
+ get_objects.assert_called_once_with(
+ mock.ANY, self._test_class.db_model, _pager=pager)
+
class BaseDbObjectNonStandardPrimaryKeyTestCase(BaseObjectIfaceTestCase):
@@ -662,6 +673,14 @@ class BaseDbObjectMultipleForeignKeysTestCase(_BaseObjectTestCase,
class BaseDbObjectTestCase(_BaseObjectTestCase):
+ CORE_PLUGIN = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2'
+
+ def setUp(self):
+ super(BaseDbObjectTestCase, self).setUp()
+ # TODO(ihrachys): revisit plugin setup once we decouple
+ # neutron.objects.db.api from core plugin instance
+ self.setup_coreplugin(self.CORE_PLUGIN)
+
def _create_test_network(self):
# TODO(ihrachys): replace with network.create() once we get an object
# implementation for networks
diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py
index 64241ae44f..60f9e3ea0b 100644
--- a/neutron/tests/unit/plugins/ml2/test_plugin.py
+++ b/neutron/tests/unit/plugins/ml2/test_plugin.py
@@ -2031,8 +2031,12 @@ class TestML2PluggableIPAM(test_ipam.UseIpamMixin, TestMl2SubnetsV2):
class TestMl2PluginCreateUpdateDeletePort(base.BaseTestCase):
+
def setUp(self):
super(TestMl2PluginCreateUpdateDeletePort, self).setUp()
+ # TODO(ihrachys): revisit plugin setup once we decouple
+ # neutron.objects.db.api from core plugin instance
+ self.setup_coreplugin(PLUGIN_NAME)
self.context = mock.MagicMock()
self.notify_p = mock.patch('neutron.callbacks.registry.notify')
self.notify = self.notify_p.start()