Merge "Add Artifact Manager service."
[ccsdk/cds.git] / ms / artifact-manager / tests / configuration_test.py
1 """Copyright 2019 Deutsche Telekom.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7     http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 """
15 from configparser import NoOptionError
16 from pathlib import Path, PurePath
17 from typing import NoReturn
18
19 from pytest import raises
20
21 from manager.configuration import ArtifactManagerConfiguration
22
23
24 TEST_CONFIGURATION_FILE_PATH = str(
25     PurePath(Path(__file__).parent.absolute(), "configuration-test.ini")
26 )
27
28
29 def test_server_configuration_configuration_file_path() -> NoReturn:
30     """Test ArtifactManagerConfiguration class.
31
32     Test checks if configuration file is loaded properly and returns valid values.
33     If invalid section or option is provided it should raises KeyError or configparser.NoOptionError exceptions.
34     :return: NoReturn
35     """
36     configuration: ArtifactManagerConfiguration = ArtifactManagerConfiguration(
37         TEST_CONFIGURATION_FILE_PATH
38     )
39     assert configuration.get_section("testSection")
40     with raises(KeyError):
41         configuration.get_section("invalidSection")
42     assert configuration.get_property("testSection", "testValue") == "123"
43     with raises(NoOptionError):
44         configuration.get_property("testSection", "invalidValue")
45     assert configuration.artifact_manager_property("artifactManagerValue") == "123"
46     with raises(NoOptionError):
47         configuration.artifact_manager_property("invalidValue")