def test_failure_debug(self):
        class AnException(Exception):
            pass

        self.args_dict['debug'] = True
        self.limit_class_result = AnException("foobar")
        with self.assertRaises(AnException):
            nova_limits.limit_class()
        self.assertEqual(self.stdout.getvalue(), '')
    def test_update(self):
        self.args_dict['klass'] = 'new_class'
        self.limit_class_result = 'old_class'
        nova_limits.limit_class()

        self.assertEqual(self.limit_class_args,
                         ('config', 'spam', 'new_class'))
        self.assertEqual(self.stdout.getvalue(),
                         'Tenant spam:\n'
                         '  Previous rate-limit class: old_class\n'
                         '  New rate-limit class: new_class\n')
    def test_noargs(self):
        self.limit_class_result = 'default'
        result = nova_limits.limit_class()

        self.assertEqual(self.limit_class_args, ('config', 'spam', None))
        self.assertEqual(self.stdout.getvalue(),
                         'Tenant spam:\n'
                         '  Configured rate-limit class: default\n')
        self.assertEqual(result, None)
    def test_delete_unset(self, mock_Config):
        db = mock_Config.return_value.get_database.return_value

        result = nova_limits.limit_class('config_file', 'spam', 'default')

        self.assertEqual(result, 'default')
        mock_Config.assert_called_once_with(conf_file='config_file')
        db.get.assert_called_once_with('limit-class:spam')
        self.assertFalse(db.set.called)
        self.assertFalse(db.delete.called)
    def test_failure(self):
        self.limit_class_result = Exception("foobar")
        result = nova_limits.limit_class()

        self.assertEqual(result, "foobar")
        self.assertEqual(self.stdout.getvalue(), '')