1 # Copyright 2021 Xoriant Corporation
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
21 from unittest import mock
22 from unittest.mock import patch
23 from pytest_mock import MockerFixture
25 from app_config import AppConfig
29 project_path = os.getcwd()
32 def get_config_path():
33 project_path=get_path()
34 config_path = os.path.join(
35 project_path,"dmaapadapter/adapter/config/adapter.conf")
45 logger = logging.getLogger('DMaaP')
46 logger.setLevel(logging.DEBUG)
47 logger.setLevel(logging.ERROR)
48 logger.setLevel(logging.INFO)
57 #test init function in appconfig
58 @mock.patch('app_config.AppConfig.setLogger')
59 @mock.patch('argparse.ArgumentParser.parse_args',
60 return_value=argparse.Namespace(config=get_config_path(),section='default'))
61 def test___init__(parser,mock_setLogger):
62 AppConfig.__init__(AppConfig)
63 mock_setLogger.assert_called_with('dmaap.log','error')
67 def test_getKafkaBroker(kafkaBroker):
68 AppConfig.kafka_broker=kafkaBroker
69 res=AppConfig.getKafkaBroker(AppConfig)
70 assert res == kafkaBroker
73 def test_getLogger(logger):
74 AppConfig.logger=logger
75 res=AppConfig.getLogger(AppConfig)
76 assert res.getEffectiveLevel()==20
79 #test logger level Info
80 def test_setLogger(logger):
83 with mock.patch.object(logger,'info') as mock_info:
84 AppConfig.setLogger(AppConfig,log_file,log_level)
85 mock_info.assert_called_with('Log level INFO and log file dmaap.log : ')
89 def test_setLogger_debug(logger):
92 with mock.patch.object(logger,'info') as mock_debug:
93 AppConfig.setLogger(AppConfig,log_file,log_level)
94 mock_debug.assert_called_with('Log level DEBUG and log file dmaap.log : ')
98 def test_setLogger_error(logger):
101 with mock.patch.object(logger,'info') as mock_error:
102 AppConfig.setLogger(AppConfig,log_file,log_level)
103 mock_error.assert_called_with('Log level ERROR and log file dmaap.log : ')
107 #test AssertConfigValue
108 def test_getAssertConfigValue(enable_assert):
109 AppConfig.enable_assert=enable_assert
110 res=AppConfig.getAssertConfigValue(AppConfig)
111 assert res==enable_assert