deb-sahara/sahara/tests/unit/test_main.py
Mate Lakat 07613622d4 Provide context for castellan config validation
When starting the API we validate castellan's config. That bit might
require a context if you have use_barbican_key_manager = true. Adding a
context to keep config checking happy.

Change-Id: I63ea1d801339afb0bf861a0a480c408aaca2e25e
Closes-Bug: #1641897
2016-11-15 13:29:40 +01:00

61 lines
1.8 KiB
Python

# Copyright (c) 2016 SUSE LINUX Products GmbH
#
# 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
import testtools
from sahara import context
from sahara import main
def mock_validate_config():
return mock.patch(
'sahara.service.castellan.config.validate_config')
class SomeException(Exception):
pass
class ValidateCastellanTest(testtools.TestCase):
def test_castellan_validate_config_called(self):
with mock_validate_config() as validate_config:
main.validate_castellan_config()
validate_config.assert_called_once_with()
def test_context_present_when_calling_validate_config(self):
def check_context():
self.assertTrue(context.has_ctx())
with mock_validate_config() as validate_config:
validate_config.side_effect = check_context
main.validate_castellan_config()
def test_context_cleared(self):
with mock_validate_config():
main.validate_castellan_config()
self.assertFalse(context.has_ctx())
def test_context_cleared_in_case_of_exception(self):
with mock_validate_config() as validate_config:
validate_config.side_effect = SomeException
self.assertRaises(SomeException, main.validate_castellan_config)
self.assertFalse(context.has_ctx())