Пример #1
0
 def test_get_objects(self):
     admin_context = self.context.elevated()
     with mock.patch.object(self.context, 'elevated',
                            return_value=admin_context) as context_mock:
         objs = self._test_class.get_objects(self.context)
     context_mock.assert_called_once_with()
     self.get_objects_mock.assert_any_call(
         admin_context, self._test_class.db_model, _pager=None)
     self.assertItemsEqual(
         [test_base.get_obj_db_fields(obj) for obj in self.objs],
         [test_base.get_obj_db_fields(obj) for obj in objs])
Пример #2
0
 def test_get_objects(self):
     admin_context = self.context.elevated()
     with mock.patch.object(self.context, 'elevated',
                            return_value=admin_context) as context_mock:
         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, _pager=None)
     self.assertItemsEqual(
         [test_base.get_obj_db_fields(obj) for obj in self.objs],
         [test_base.get_obj_db_fields(obj) for obj in objs])
Пример #3
0
 def test_get_objects_sort_by_order_asc(self):
     self._create_dnsnameservers()
     objs = self._test_class.get_objects(self.context)
     fields_sorted = sorted([dict(obj) for obj in self.obj_fields],
                            key=itemgetter('order'))
     self.assertEqual(
         fields_sorted,
         [obj_test_base.get_obj_db_fields(obj) for obj in objs])
Пример #4
0
 def test_get_objects_sort_by_order_asc(self):
     self._create_dnsnameservers()
     objs = self._test_class.get_objects(self.context)
     fields_sorted = sorted([dict(obj) for obj in self.obj_fields],
                            key=itemgetter('order'))
     self.assertEqual(
         fields_sorted,
         [obj_test_base.get_obj_db_fields(obj) for obj in objs])
Пример #5
0
 def test_get_objects_sort_by_address_asc_using_pager(self):
     self._create_dnsnameservers()
     pager = obj_base.Pager(sorts=[('address', True)])
     objs = self._test_class.get_objects(self.context, _pager=pager)
     fields_sorted = sorted([dict(obj) for obj in self.obj_fields],
                            key=itemgetter('address'))
     self.assertEqual(
         fields_sorted,
         [obj_test_base.get_obj_db_fields(obj) for obj in objs])
Пример #6
0
 def test_get_objects_sort_by_address_asc_using_pager(self):
     self._create_dnsnameservers()
     pager = obj_base.Pager(sorts=[('address', True)])
     objs = self._test_class.get_objects(self.context, _pager=pager)
     fields_sorted = sorted([dict(obj) for obj in self.obj_fields],
                            key=itemgetter('address'))
     self.assertEqual(
         fields_sorted,
         [obj_test_base.get_obj_db_fields(obj) for obj in objs])
Пример #7
0
 def test_get_objects_sort_by_order_desc(self):
     self._create_dnsnameservers()
     pager = obj_base.Pager(sorts=[('order', False)])
     objs = self._test_class.get_objects(self.context, _pager=pager,
                                         subnet_id=self._subnet.id)
     fields_sorted = sorted([dict(obj) for obj in self.obj_fields],
                            key=itemgetter('order'), reverse=True)
     self.assertEqual(
         fields_sorted,
         [obj_test_base.get_obj_db_fields(obj) for obj in objs])
Пример #8
0
 def test_get_objects_sort_by_order_desc(self):
     self._create_dnsnameservers()
     pager = obj_base.Pager(sorts=[('order', False)])
     objs = self._test_class.get_objects(self.context,
                                         _pager=pager,
                                         subnet_id=self._subnet.id)
     fields_sorted = sorted([dict(obj) for obj in self.obj_fields],
                            key=itemgetter('order'),
                            reverse=True)
     self.assertEqual(
         fields_sorted,
         [obj_test_base.get_obj_db_fields(obj) for obj in objs])
Пример #9
0
 def test_get_object(self):
     admin_context = self.context.elevated()
     with mock.patch.object(db_api, 'get_object',
                            return_value=self.db_obj) as get_object_mock:
         with mock.patch.object(self.context,
                                'elevated',
                                return_value=admin_context) as context_mock:
             obj = self._test_class.get_object(self.context, id='fake_id')
             self.assertTrue(self._is_test_class(obj))
             self.assertEqual(self.db_obj, test_base.get_obj_db_fields(obj))
             context_mock.assert_called_once_with()
             get_object_mock.assert_called_once_with(
                 admin_context, self._test_class.db_model, id='fake_id')