def test_import_class_or_object(self): # Test that import_class raises a descriptive error when the # class to import could not be found. self.assertRaises(exception.ImportFailure, utils.import_class, 'nomodule') self.assertRaises(exception.ImportFailure, utils.import_class, 'mymodule.nonexistingclass') self.assertRaises(exception.ImportFailure, utils.import_class, 'sys.nonexistingclass') self.assertRaises(exception.ImportFailure, utils.import_object, 'os.path.NONEXISTINGOBJECT') store_class = utils.import_class('glance.store.s3.Store') self.assertTrue(store_class.__name__ == 'Store') # Try importing an object by supplying a class and # verify the object's class name is the same as that supplied ex_obj = utils.import_object('glance.common.exception.GlanceException') self.assertTrue(ex_obj.__class__.__name__ == 'GlanceException') # Try importing a module itself module_obj = utils.import_object('glance.registry') self.assertEqual('glance.registry', module_obj.__package__)
def setUp(self): def _fake_connect(rabbit_self): rabbit_self.connection_errors = () rabbit_self.connection = 'fake_connection' return None self.notify_kombu = common_utils.import_object( "glance.notifier.notify_kombu") self.notify_kombu.RabbitStrategy._send_message = self._send_message self.notify_kombu.RabbitStrategy._connect = _fake_connect self.called = False self.conf = utils.TestConfigOpts({"notifier_strategy": "rabbit", "rabbit_retry_backoff": 0, "rabbit_notification_topic": "fake_topic"}) self.notifier = notifier.Notifier(self.conf)
def setUp(self): def _fake_connect(rabbit_self): rabbit_self.connection_errors = () rabbit_self.connection = 'fake_connection' return None self.notify_kombu = common_utils.import_object( "glance.notifier.notify_kombu") self.notify_kombu.RabbitStrategy._send_message = self._send_message self.notify_kombu.RabbitStrategy._connect = _fake_connect self.called = False self.conf = utils.TestConfigOpts({ "notifier_strategy": "rabbit", "rabbit_retry_backoff": 0, "rabbit_notification_topic": "fake_topic" }) self.notifier = notifier.Notifier(self.conf)
def setUp(self): if not qpid: return self.mocker = mox.Mox() self.mock_connection = None self.mock_session = None self.mock_sender = None self.mock_receiver = None self.orig_connection = qpid.messaging.Connection self.orig_session = qpid.messaging.Session self.orig_sender = qpid.messaging.Sender self.orig_receiver = qpid.messaging.Receiver qpid.messaging.Connection = lambda *_x, **_y: self.mock_connection qpid.messaging.Session = lambda *_x, **_y: self.mock_session qpid.messaging.Sender = lambda *_x, **_y: self.mock_sender qpid.messaging.Receiver = lambda *_x, **_y: self.mock_receiver self.notify_qpid = common_utils.import_object( "glance.notifier.notify_qpid") super(TestQpidNotifier, self).setUp()